Path: utzoo!attcan!ncrcan!hcr!stan From: stan@hcr.UUCP (Stan Jarzabek) Newsgroups: comp.lang.c++ Subject: deleting objects with virtual bases Message-ID: <1984@hcr.UUCP> Date: 7 Sep 89 14:17:06 GMT Reply-To: stan@hcrvx1.UUCP (Stan Jarzabek) Organization: HCR Corporation, Toronto Lines: 30 Is it legal to delete an object with a virtual base through base pointer? class A { int a; }; class B : virtual public A { int b; }; class C : public B { int c; }; main() { A* ap = new C; delete ap; C* cp = new C; //core dumped } As 'ap' does not really point to the beginning of the area allocated by 'new C', 'delete ap' causes a problem. (In 2.0, operator delete() calls free().) In fact, a subsequent call to operator new() causes core dump. The same problem may occur when you delete an object with multiple bases through a base pointer. The language manual does not address this issue: is this a language definition problem, the problem of current implementation, or the thing a user should be responsible for? Stan Jarzabek