Class and SubClass

Hello, I have a class and I want to have a subclass from that.

a) How do I code that?
b) A class can acess to the private members from the subclass?
A)

1
2
3
4
5
6
7
8
9

class fruit {

};

class apple : public fruit  {

};


B) You can't. That would defeat the whole point of having private members. You can however, declare those members as protected, which allows only derived classes (its subclasses) to access them.
Topic archived. No new replies allowed.