Inheritance

Hello programmers,

I have a question regarding Inheritance, Is it possible to have a derived class of a private base class?

Thanks in advance
When you say private base class, do you mean struct Bat in
1
2
3
4
5
6
7
8
9
struct Ant{
private:
   struct Bat{};

public:
   struct Dot : Bat{};
};

struct Cat : Ant::Bat{};

Here Dot is ok, but Cat will produce an error.
Yes, I was reading about getters and setters and the point that I got is that one can access private members of a class from outside of a class by using getters and setters,

am I right?
Only Ant can use Bat, Bat doesn't exist outside of Ant because it's private. Ant can use Bat objects and access data members the same way you can access data members from an Ant object in a function.
You may also use the access modifier protected: to hide members outside of the class hierarchy.
Topic archived. No new replies allowed.