Re: Implementation of abstract classes
On Sep 20, 6:07 pm, Rune Allnor <all...@tele.ntnu.no> wrote:
I have some classes which are derived from some base:
class base {
void foo();
void bar();
};
class a : public base {
};
class b: public base{
};
The problem is as follows:
1) I would like to prevent users from making instances of
class base
2) There are no overloaded functions beween the base class
and the derived classes, so I can not use the usual
virtual void overloaded_function() = 0;
in the base class.
As far as I can see, there are two ways to proceed:
1) make some virtual dummy function that the
derived classes need to implement
2) Hide the constructor of base as protected.
From a semantic point of view the latter solution
seems the more elegant. Is this a good solution
or are there traps or snags associated with it?
I don't know about elegance, but the second solution is
certainly the usual solution.
--
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