Use of “Public” in a derived class declaration?

后端 未结 3 1416
长发绾君心
长发绾君心 2020-12-13 14:02

Given this base class:

class Employee
{
     char* name;
     int age;

  public:
     Employee(char* name);
     void print();
};

With reg

3条回答
  •  轮回少年
    2020-12-13 14:29

    In C++, inheritance is private by default. However, to any code using the Manager class, there appears to be almost no difference, since they have the same methods.

    You won't be able to cast the Manager object to an Employee, though. You also won't be able to access the employees variable from within the Manager class.

提交回复
热议问题