From: red floyd on
red floyd wrote:
>
Darn, forgot one critical element.

[redacted]

struct ok_to_instantiate : public i_cant_be_instantiated

[redacted]

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andrew Koenig on
"Ron Natalie" <ron(a)spamcop.net> wrote in message
news:45ed8ca7$0$7450$9a6e19ea(a)news.newshosting.com...
> sk.smawsk(a)gmail.com wrote:

>> Can there be any use of "Pure Virtual Destructor"?
>> If yes, then in what scenario do we use it?

> Certainly, you can. It's not tremendously useful
> other than to force a class to be abstract in the
> absence of any other pure methods.

> Note that the pure virtual destructor is still called
> when the derived class is destroyed so you need to have
> an implementation of it.

But it's not really useful for that purpose either, because using it
that way forces you to define a destructor that is almost surely useless
becasue it has nothing to destroy.

I don't like being required to write dead code.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Francis Glassborow on
In article <1173196295.237848.323320(a)s48g2000cws.googlegroups.com>, Val
<valosmith(a)gmail.com> writes
>You can't have a pure virtual destructor if the compiler is following
>the language spec. If you were to derive a concrete class from the
>abstract one, then create and destroy an object, the base class's
>destructor would be invoked immediately before the derived
>destructor. If the base destructor isn't implemented, then this is a
>problem.

No, making a function a pure virtual does not prevent you from
implementing it. All it does is to require that ever derived concrete
class has an implementation (possibly inherited from an intermediate
derived class)

--
Francis Glassborow ACCU
Author of 'You Can Do It!' and "You Can Program in C++"
see http://www.spellen.org/youcandoit
For project ideas and contributions:
http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: James Kanze on
On Mar 7, 2:12 am, "Andrew Koenig" <a...(a)acm.org> wrote:
> "Ron Natalie" <r...(a)spamcop.net> wrote in message

> news:45ed8ca7$0$7450$9a6e19ea(a)news.newshosting.com...

> > sk.sma...(a)gmail.com wrote:
> >> Can there be any use of "Pure Virtual Destructor"?
> >> If yes, then in what scenario do we use it?
> > Certainly, you can. It's not tremendously useful
> > other than to force a class to be abstract in the
> > absence of any other pure methods.
> > Note that the pure virtual destructor is still called
> > when the derived class is destroyed so you need to have
> > an implementation of it.

> But it's not really useful for that purpose either, because using it
> that way forces you to define a destructor that is almost surely useless
> becasue it has nothing to destroy.

> I don't like being required to write dead code.

But as soon as you need a virtual destructor, you're in that
case anyway.

I'll admit that the virtual destructor of a class in which all
other functions are pure virtual is the one case I'll use a
function definition directly in the class---which I couldn't do
if the destructor were pure virtual. (It leads to the somewhat
curious situation that the only function I have which is inline
is virtual. But I'm not going to create a separate .cc file
just for a single, empty function.)

--
James Kanze (GABI Software) email:james.kanze(a)gmail.com
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



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: James Kanze on
On Mar 7, 2:13 am, Francis Glassborow <fran...(a)robinton.demon.co.uk>
wrote:
> In article <1173196295.237848.323...(a)s48g2000cws.googlegroups.com>, Val
> <valosm...(a)gmail.com> writes

> >You can't have a pure virtual destructor if the compiler is following
> >the language spec. If you were to derive a concrete class from the
> >abstract one, then create and destroy an object, the base class's
> >destructor would be invoked immediately before the derived
> >destructor. If the base destructor isn't implemented, then this is a
> >problem.

> No, making a function a pure virtual does not prevent you from
> implementing it. All it does is to require that ever derived concrete
> class has an implementation (possibly inherited from an intermediate
> derived class)

That's right, but maybe a bit confusing. What it means is that
until at least one class on a direct path from the most derived
class to the base class has a user declared (and defined)
destructor, the class is abstract, and cannot be instantiated.
What declaring the destructor pure virtual does, in practice, is
to require every derived class to provide a user defined
destructor, even when it wouldn't need one otherwise.

IMHO, this is not a good idea.

--
James Kanze (GABI Software) email:james.kanze(a)gmail.com
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



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]