I know that the derived class can’t access the private members of the base class, so why does the derived class inherit the private members of the base class? Is there any case that it is useful?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The derived class needs the private members even though it can’t access them directly. Otherwise it’s behavior would not build on the class it is deriving from.
For example, pretend the private stuff is:
and the class has a geti() and seti(). The value of i has to be put somewhere, even if it is private,