Path: utzoo!attcan!uunet!cbmvax!daveh From: daveh@cbmvax.UUCP (Dave Haynie) Newsgroups: comp.lang.c++ Subject: Virtual Destructors? Message-ID: <5568@cbmvax.UUCP> Date: 22 Dec 88 23:53:57 GMT Organization: Commodore Technology, West Chester, PA Lines: 46 I'm pretty new to this C++ game, but I've already run into something that doesn't make sense. Perhaps this is already fixed -- I'm using Lattice C++ V1.00 on the Amiga, which is based on cfront V1.1a. In any case, I can't figure out why in the world destructors aren't virtual. Basically, I have this situation that looks pretty much like the following: class A { ... A(..) {...} ~A( ) {...} ... }; class B : public A { ... B(..) : (...) {...} ~B( ) {...} ... }; ... // Much later A tool; if (thing) tool = new A(...); else tool = new B(...); ... // Yet again even later delete tool; No problem, except that when I delete tool, I always get A's destructor, not B's. Certainly I can take care of this problem by having each destructor call a virtual function which does the actual destroying, but I can't think of any good reason for destructors to not be virtual. Is this really a problem, or am I missing something really obvious? -- Dave Haynie "The 32 Bit Guy" Commodore-Amiga "The Crew That Never Rests" {uunet|pyramid|rutgers}!cbmvax!daveh PLINK: D-DAVE H BIX: hazy Amiga -- It's not just a job, it's an obsession