Hot answers tagged

4

Derived derivedObj; is a local variable. It's deleted when the function exits. You have saved a pointer to it, but with that object now gone your pointer points to nothing of any interest - so doing anything with it is doomed to failure. Instead you need to create a new object on the heap, which will already be a pointer: Derived *derivedObj = new Derived(); ...


Only top voted, non community-wiki answers of a minimum length are eligible