A void
pointer has no type information. If MyClass
has a destructor, it will not be called. The compiler needs to know what it is deleting so it can generate the appropriate code. If all of your pointers in the list are of the same type then you should be storing that type in the list, not as void
. If the pointers are different types but derive from a common base type, then give that base type a virtual constructor and store pointers of that type instead.