C++ Class Inheritance architecture - preventing casting
- by Some One
I have a structure of base class and a couple of inherited classed.
Base class should be pure virtual class, it should prevent instantiation.
Inherited classes can be instantiated.
Code example below:
class BaseClass
{
public:
BaseClass(void);
virtual ~BaseClass(void) = 0;
};
class InheritedClass : public BaseClass
{
public:
InheritedClass1(void);
~InheritedClass1(void);
};
class DifferentInheritedClass : public BaseClass
{
public:
DifferentInheritedClass(void);
~DifferentInheritedClass(void);
};
I want to prevent the following operations to happen:
InheritedClass *inherited1 = new InheritedClass();
DifferentInheritedClass *inherited2 = new DifferentInheritedClass ();
BaseClass *base_1 = inherited1;
BaseClass *base_2 = inherited2;
*base_1 = *base_2;