Topic: Force refinement of a class (was Q: Prevent refinement of a class?)
Author: jim.hyslop@leitch.com
Date: 1998/10/15 Raw View
[ moderator's note: This discussion has moved away from the
C++ standard to programming style. I've redirected followups
to comp.lang.c++ only. -sdc ]
In article <70320f$6ek@handupme.avid.com>,
paul@ra.avid.com (Paul Miller) wrote:
[snip]
> You can also make the constructor/destructor protected to
> guarantee that it only functions as a base class - ie. that
> it MUST be derived from.
What is the advantage of that method, over declaring one or more member
functions pure virtual? After all, the sole reason pure virtual functions
exist is to prevent instantiation of the base class itself.
You will likely have to make the destructor virtual (unless you can absolutely
guarantee that the derived objects will *never* be deleted polymorphically,
either now or in code that is written in the future). That eliminates the
argument about virtual functions increasing object size.
So, what are the pros and cons of each method?
Jim
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]