c++ - Will using delete with a base class pointer cause a memory leak? -


given 2 classes have primitive data type , no custom destructor/deallocator. c++ spec guarantee deallocate correct size?

struct { int foo; }; struct b: public { int bar[100000]; }; *a = (a*)new b; delete a; 

i want know need write empty virtual dtor?

i have tried g++ , vc++2008 , won't cause leak. know correct in c++ standard.

unless base class destructor virtual, it's undefined behaviour. see 5.3.5/4:

if static type of operand [of delete operator] different dynamic type, static type shall base class of operand's dynamic type , static type shall have virtual destructor or behaviour undefined.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -