I have following problem:
- want to inherit some class as protected (outside derived class i dont need any member or function from base class)
- want to be able to access base constructor in some way
Here is an example (compile error):
class Animal
{
public:
explicit Animal(void){;}
};
class Dog: private Animal
{
public:
explicit Dog(void){;}
};
int main(int argc, char *argv[])
{
Dog* pDog1 = new Dog();
Animal* pDog2 = new Dog();
return 0;
}
How can I solve this?
Thanks!
edit: Let’s say that Base class is inherited from some library thus i cant change it.
As an alternative to reinterpret_cast, you may expose the base class with a method. If one day you decide to use composition instead of inheritance, it won’t break your code: