0
点赞
收藏
分享

微信扫一扫

罗德与施瓦茨联合广和通全面验证RedCap模组FG132系列先进性能

舟海君 03-21 14:00 阅读 2
class person {
public:
	void func() {
		cout <<"_name "<< _name << endl;
		cout << "_age " << _age << endl;
	}
protected:
	string _name="abc";
	int _age=0;
};
class student :public person {//public就是继承方式

protected:
	int _s_id;
};
class teacher :public person {

protected:
	int _t_id;
};
int main() {
	student s1;
	s1.func();
	return 0;
}
类成员/继承方式public继承protected继承private继承
基类的public成员派生类的public成员派生类的protected成员派生类的private成员
基类的protected成员派生类的protected成员派生类的protected成员派生类的private成员
基类的private成员在派生类中不可见在派生类中不可见在派生类中不可见

class person {
public:
	person(const char* s="Tony", int n=10)
		:_name(s)
		,_age(n)
	{}
protected:
	string _name;
	int _age;
};

class student :public person {
public:
	student(const char* s = "Tony", int age = 10, int id = 1)
		:_s_id(id)
		, person(s, age)
	{}
protected:
	int _s_id;
};

class A {
public:
//protected:
	int _a;
};
class B :public A{
public:
//protected:
	int _b;
};
class C:public A {
public:
//protected:
	int _c;
};
class D :public B, public C {
public:
//protected:
	int _d;
};

int main() {
	D dd;
	dd._a = 10;//不明确
	return 0;
}

举报

相关推荐

0 条评论