   Destructor isn't called
  Hi!I have a list with blocks in my game. It is of the type "BasicBlock*", but also holds classes like LevelBlock* or TexturedBlock* and others which extend the BasicBlock class.But when I call this:void SceneManager::DeleteBlock(BasicBlock* Which){list<BasicBlock *>::iterator it;for(it=Blocks.begin();it!=Blocks.end();it++){if((*it)==Which){delete Which;Blocks.erase(it);break;}}} only the destructor from the BasicBlock-class gets called!Here are two of my classes:BasicBlock.h#pragma once#include "Direct2D_Vars.h"#include "SceneManager.h"class BasicBlock{public:BasicBlock(void);~BasicBlock(void);//...BasicBlock.cpp#include "BasicBlock.h"BasicBlock::BasicBlock(void){MyClass=BASICBLOCK;bSaveBlockInMapfile=true;}BasicBlock::~BasicBlock(void){//This gets called}//...LevelBlock.h#pragma once#include "BasicBlock.h"#include "PhysicalComponent.h"class LevelBlock : public BasicBlock{public:LevelBlock(void);~LevelBlock(void);//...LevelBlock.cpp#include "LevelBlock.h"LevelBlock::LevelBlock(void){Position=D3DXVECTOR3(0,0,0);Scale=D3DXVECTOR2(50,50);Roundness=0;RigidBody=NULL;Rotation=0;MyClass=LEVELBLOCK;}LevelBlock::~LevelBlock(void){//This never gets calledPhysics.DynamicsWorld->removeRigidBody(RigidBody);delete RigidBody;delete CollisionShape;delete myMotionState;}//...I don't think that is the normal behavior, or is it? I never noticed that before if so.   
  Destructors for base classes should be virtual under most normal circumstances.   ;  That solved the problem, but it worked without it before many many times ...   ;Quote:Original post by mind in a boxThat solved the problem, but it worked without it before many many times ...No it didn't.If you delete a pointer to a class without a virtual destructor, only the destructor for that specific class is called, which in turn calls the destructors of any parent classes.If the pointer happens to actually point to a more derived class and the destructor is not virtual, the compiler has no way to know which destructor to start by calling.class A{public:    ~A(){ } // not virtual};class B{public:    ~B(){ }};void f(){    A *a=new B();    delete a; // only A::~A() will be called};  Ah, I believed my book here. I guess I have to update some code. [smile]I never got any memory leaks and such stuff without using "virtual" with destructors. Maybe there was just some wired stuff going on :-/   ;  If you weren't hitting that destructor then the 'delete's in that constructor were never being called. Unless those pointers were already null, or deleted elsewhere, it seems like that could cause a memory leak.   