草庐IT

virtual-tour

全部标签

c++ - 初学者 c++ : virtual functions in a base class

我正在编写一些代码,其中我定义了以下基类。classChorus{public://Destructorvirtual~Chorus();//callbackfunctionvirtualintcallback(void*outputBuffer,void*notUsed,unsignedintnBufferFrames,doublestreamTime,RtAudioStreamStatusstatus,void*userData);virtualvoidinitializeDelayBuffer(void);virtualvoiddestroyDelayBuffer(void);}

C++ 继承 : does lack of virtual destructor lead to memory leak?

这个问题在这里已经有了答案:Possiblememoryleakwithoutavirtualdestructor?(3个答案)关闭6年前。我对自己经常问自己的一个问题有疑问,是这样的情况:两个类,没有虚析构函数classBase{intmyInt;};classDerived:publicBase{intmyIntDerived;};intmain(){Base*base=newDerived;Derived*derived=newDerived;deletebase;deletederived;}第一个delete导致内存泄漏而第二个delete没问题,这样说对吗?

SourceCodester Online Tours & Travels Management System payment.php sql injection

path:admin/operations/payment.phpAbstract:Line43ofpayment.phpinvokesaSQLquerybuiltwithinputthatcomesfromanuntrustedsource.Thiscallcouldallowanattackertomodifythestatement’smeaningortoexecutearbitrarySQLcommands.Explanation:SQLinjectionerrorsoccurwhen:Dataentersaprogramfromanuntrustedsource.Thedatais

c++ - 海湾合作委员会 : C++11 inline object initialization (using "this") does not work when there is a virtual inheritance in hierarchy

当在初始化中使用此指针并且在层次结构中存在虚拟继承时,C++11内联对象初始化不起作用(在GCC中)。这可能是GCC的错误吗(因为它在CLang中工作)?还是C++11标准本身的差距?示例(可以在here中尝试),当使用GCC编译以下代码时:FieldIndexm_inB{"inB",this};不会被执行。但它会在使用CLang编译时执行。变通方法:从FieldIndexContainer派生A作为虚拟#include#include#includeusingnamespacestd;classFieldIndexContainer{public:classFieldIndex{pu

c++ - 使用 protected 非虚拟析构函数时抑制 delete-non-virtual-dtor 警告

我有一个纯抽象接口(interface)类和一个实现该接口(interface)的派生类。structFoo{virtualvoiddoStuff()=0;};structBar:Foo{voiddoStuff()override{}};我的接口(interface)类没有虚拟析构函数。因此,尝试使用基类指针破坏派生实例显然是未定义的行为intmain(){Foo*f=newBar;f->doStuff();deletef;}幸运的是我的编译器足够聪明,可以捕捉到这个(使用-Werror)main.cc:15:9:error:deletingobjectofabstractclasst

c++ - 如何解决 : undefined reference to `non-virtual thunk to ...`

我正在尝试弄清楚如何进一步解决此问题。我还想知道如何安装更新版本的ld(如果有意义的话)。所有涉及的包管理器都告诉我,我是最新的。代码在ubuntu12.04和12.10上使用g++(4.7.2)编译、链接和运行,但在FC17上编译失败并出现此错误。ArchiveServiceLib/debug-posix/libArchiveLib.a(NamedIflTiffCache.o):(.rodata._ZTV26UnlockingGenericFileHandle[_ZTV26UnlockingGenericFileHandle]+0x58):undefinedreferenceto`I

C++ : noexcept (or throw()) virtual destructor = default;

下面的代码是合法的吗?classC{virtual~C()noexcept=default;};或classC{virtual~C()throw()=default;};(throw()已弃用,但我的编译器不支持noexcept;;) 最佳答案 8.4.2[dcl.fct.def.default]Anexplicitly-defaultedfunction[...]mayhaveanexplicitexception-specificationonlyifitiscompatible(15.4)withtheexception-spe

SourceCodester Online Tours & Travels Management System expense.php sql injection

SourceCodesterOnlineTours&TravelsManagementSystemexpense.phpsqlinjectionUrl:admin/operations/expense.phpAbstract:Line47ofexpense.phpinvokesaSQLquerybuiltusingunvalidatedinput.Thiscallcouldallowanattackertomodifythestatement’smeaningortoexecutearbitrarySQLcommands.Explanation:SQLinjectionerrorsoccurw

c++ - 通常方法上的 Woverloaded-virtual 警告

我很困惑为什么下面的代码会产生Woverloaded-virtual警告。classTestVirtual{public:TestVirtual();virtualvoidTestMethod(inti);};classDerivedTestVirtual:publicTestVirtual{public:voidTestMethod();};派生类具有不带参数的常用方法TestMethod-签名不同于基类的类似虚拟方法。那为什么编译器不能解决这种情况呢? 最佳答案 警告的原因是无参数版本从基类中隐藏了int版本。DerivedTe

C++ 重载 virtual = 运算符

这是我的问题的代码:classICommon{public:virtualICommon&operator=(constICommon&p)const=0;};classCSpecial:publicICommon{public:CSpecial&operator=(constCSpecial&cs)const{//customoperationsreturn*this;}};CSpecialobj;基本上:我希望接口(interface)ICommon强制其后代实现=运算符,但不希望在实现中有任何类型转换。编译器说“无法实例化抽象类。任何帮助/建议将不胜感激。