栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++继承中属性对象重名和多父类继承

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++继承中属性对象重名和多父类继承

#include
#include
using namespace std;
class fa {
public:
	int m = 1000;
	void shuchu() {
		cout << "fa类的shuchu对象"<
		cout << "fa类的shuchu对象的int重载"<
public:
	int m = 100;
	void shuchu() {
		cout << "son类的shuchu对象"<
	son s;
	cout << "同名成员属性处理方法" << endl;
	cout << "son下 m=" << s.m << endl;
	cout << "fa下  m=" << s.fa::m << endl;
	cout << "同名成员函数处理方法" << endl;
	cout << "son下的函数:" << endl;
	s.shuchu();
	cout << "nfa下的函数:" << endl;
	s.fa::shuchu();//调用父类需要作用域
	//s.shuchu(100);//报错
	s.fa::shuchu(100);
}
int main() {
	ceshi();
}

//cpp允许一个类继承多个类
#include
#include
using namespace std;
//cpp允许一个类继承多个类
//【实际开发不建议】
class fa_1 {
public:
	int m1 = 1;
};
class fa_3 {
public:
	int m3 = 3;
};
class fa_2 {
public:
	int m2 =2;
};
class son :public fa_1, public fa_2, public fa_3 {
public:
	int m2 = 4;
};
int main() {
	son s;
	cout << "sizeof  = " << sizeof(s)<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/867218.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号