As shown there is no problem with the program when a stub ClassP
is added that does nothing (and class
is added where required, and main()
changed to return int
). The behavior you observe may be due to a corruption of the memory.
If any or all of ClassA
, ClassB
or ClassP
actually have non-trivial destructors, it is possible that at least one of their destructor implementations has a bug that is causing undefined behavior. You should focus your attention on that.
Realize that std::auto_ptr
has been deprecated, and you should use std::unique_ptr
instead, as noted by Ben Voigt.