Re: Regarding Abstract Class
On Sep 23, 4:34 pm, Pranav <pranav...@gmail.com> wrote:
I have a simple question regarding the definition of abstract
class, IIRC , Abstract class is one which contains virtual
function declaration and other variables and no object of this
class is created directly.
An abstract class is one which has at least one pure virtual
function. Most of the time, it will have more than one virtual
function, and no data, but these aren't formal requirements.
If this is the case why don't we hide the constructor of
abstract class into protected region?
We do, if we have to provide a constructor. Since most abstract
classes have no data, it's frequent not to bother declaring a
constructor at all. Which means that the compiler will generate
a public one. But since the class is abstract, the compiler
won't let you create an instance anyway, it doesn't matter.
In the cases where you have an interface in which none of the
functions are pure virtual, it is usual to declare and define a
protected constructor, even if it is empty. (Such cases aren't
frequent, but sometimes occur in event notifiers and such, where
the interface provides a default implementation which ignores
the event, so client code need only override the functions for
the events it's actually interested in.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34