Deleting objects using abstract base class pointers
-
Hi, I have an abstract base class Graph which has concrete child classes Grid and Puzzle. To keep the code general, I use pointers to the base class Graph and instantiate them to either Grid or Puzzle objects. This works fine until I have to delete any of these, where I get the "Debug Assertion Failed!", "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" error. For example: Grid *g = new Grid(); delete g; works, but Graph *g = new Grid(); delete g; doesn't. Does anybody know why this is? Any help would be greatly appreciated.
-
Hi, I have an abstract base class Graph which has concrete child classes Grid and Puzzle. To keep the code general, I use pointers to the base class Graph and instantiate them to either Grid or Puzzle objects. This works fine until I have to delete any of these, where I get the "Debug Assertion Failed!", "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" error. For example: Grid *g = new Grid(); delete g; works, but Graph *g = new Grid(); delete g; doesn't. Does anybody know why this is? Any help would be greatly appreciated.
-
Hi, I have an abstract base class Graph which has concrete child classes Grid and Puzzle. To keep the code general, I use pointers to the base class Graph and instantiate them to either Grid or Puzzle objects. This works fine until I have to delete any of these, where I get the "Debug Assertion Failed!", "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" error. For example: Grid *g = new Grid(); delete g; works, but Graph *g = new Grid(); delete g; doesn't. Does anybody know why this is? Any help would be greatly appreciated.
Graph *g = new Grid(); delete g; It works fine for me.
-
Is the destructor for your base class virtual? Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
Is the destructor for your base class virtual? Tim Smith I'm going to patent thought. I have yet to see any prior art.
I can't find any relation between the base class virtual/non virtual destructor and
delete
operator. Could you explain your message?