关于继承的成员的问题
子类不能直接使用父类的成员吗?比如初始化成员变量?
编译器在子类那name那里提示错误,说是“name不是类CollegeStudent的非静态数据成员或基类”,这是咋回事?
我的理解是,子类继承了基类的非protected变量,作为自己的成员变量来用,可以这样不?
class Student
{
public:
Student() : name("Student"), sex('M'), age(18), num("1") {}
Student(string n, char s, int a, string no) : name(n), sex(s), age(a), num(no) {}
protected:
int age;
string name;
char sex;
string num;
};
class CollegeStudent : public Student
{
public:
CollegeStudent(string n, char s, int a, string no) : name("CollegeStudent") {}
};
编译器在子类那name那里提示错误,说是“name不是类CollegeStudent的非静态数据成员或基类”,这是咋回事?
我的理解是,子类继承了基类的非protected变量,作为自己的成员变量来用,可以这样不?
...全文
相关推荐
C++多重继承引发的重复调用问题与解决方法
主要介绍了C++多重继承引发的重复调用问题与解决方法,结合具体实例形式分析了C++多重调用中的重复调用问题及相应的解决方法,需要的朋友可以参考下
多重继承(6_7钻石继承问题)_C++_
多重继承(6_7钻石继承问题)多重继承(6_6)多重继承(6_7钻石继承问题)多重继承(6_6)
C继承多继承PPT学习教案.pptx
C继承多继承PPT学习教案.pptx
c++基础语法:虚继承
虚继承 的概念的提出主要是为了解决C++多继承的问题,举个最简单的例子: 代码如下:class animal{ public : void op() {cout << “hello animal” ;} };class tiger : public animal { public : void tg() {cout << “this is tiger” ;}};class lion : public animal { public
实现C++类的多重继承
实现C++类的多重继承


