gpuchtel wrote:
> On Jul 4, 4:38 am, James Kanze <james.ka...@gmail.com> wrote:
> > The first is the virtual destructor of an "interface", e.g.:
> > class Interface
> > {
> > public:
> > virtual ~Interface() {}
> > // Only pure virtual functions...
> > } ;
> > Since the destructor is the only function which has an
> > "implementation", it seems a shame to have to create a source
> > file just for it. (And of course, the destructor never will be
> > called virtually, since instances of the class can't exist.)
> Actually, an instance of the 'Interface' class does exist,
When I speak of an instance, I'm using the usual meaning: an
object with type Interface. Obviously, the derived classes will
have a sub-object of type Interface, and during construction and
destruction, there will be a moment when the dynamic type of the
object is Interface (but with the above destructor, and the
compiler provided constructors, there's no way a program can
actually see this) but there can be no fully constructed object
of type Interface.
> it's just that it cannot be instantiated explicitly;
Or implicitly.
> however, the compiler will create it.
When?
> Furthermore, the destructor of the abstract (Interface)
> class 'is' called,
But it's never called "virtually". Whenever the compiler calls
it, it knows exactly that destructor is being called. (That's
why you can declare it pure virtual.) At least read what you
are responding to.
--
James Kanze (Gabi Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34