[Please do not mail me a copy of your followup]
What book is this you're reading so I can make sure *not* to recommend
it to anyone? LOL. I find the snippets you're posting to leave a
reader new to the language more confused than enlightened and they
often seem to exhibit poor practices and conventions. Introducing
someone to the language with poor practices and conventions is IMO a
really bad way to teach C++.
fl <
rxj...@gmail.com> spake the secret code
<
265510a8-466d-4f31...@googlegroups.com> thusly:
>I remember that the derived class of Number should have a real
> ~Number();
If a class is designed to be used as a base class with virtual methods
that provide 'extension points' from the base class, such a base class
should have a virtual destructor.
The reason for this is that virtual methods are the mechanism by which
we obtain run-time polymorphism for a class hierarchy. In such a
sitaution, the user of such class is interacting with the class
through a pointer to the base class. When an instance of the class is
destroyed by operator delete, the virtual destructor ensures that the
destructor associated with the actual derived instance of the base is
invoked. If the destructor were not virtual, only the base class
would be destroyed and the object would not be properly destroyed.
>Now, class Number has both virtual and member function
>~Number().
It declares the destructor virtual and then defines the destructor.
> virtual ~Number();
This is a declaration.
>Number::~Number()
>{
> if (rep && --rep->referenceCount == 0)
> delete rep;
>}
This is a definition. When a virtual method is defined outside the
class declaration, the 'virtual' keyword is not allowed because only
declarations are marked virtual, not definitions.
--
"The Direct3D Graphics Pipeline" free book <
http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <
http://computergraphicsmuseum.org>
The Terminals Wiki <
http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <
http://legalizeadulthood.wordpress.com>