在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
基类与派生的构造函数的调用顺序。创建时先基类后派生类。销毁时先派生类后基类。 当有参数时,参数必须传送给基类。注意例子中传递的方法。 #include <iostream> #include <string> using namespace std; class CBase { string name; public: CBase(string s) : name(s) { cout << "BASE: " << name << endl; } ~CBase() { cout << "~BASE" << endl; } }; class CDerive : public CBase { int age; public: CDerive(string s, int a) : CBase(s), age(a) { cout << "DERIVE: " << age << endl; } ~CDerive() { cout << "~DERIVE" << endl; } }; int main ( ) { CDerive d("小雅", 27); return 0; } 输出; BASE: 小雅 深入: http://www.cnblogs.com/kekec/archive/2010/11/16/1878783.html http://ticktick.blog.51cto.com/823160/294573 http://www.cnblogs.com/xkfz007/archive/2012/05/11/2496447.html http://topic.csdn.net/t/20060323/14/4634776.html http://see.xidian.edu.cn/cpp/biancheng/view/232.html
http://www.quanxue.cn/JC_CLanguage/Cpp/Cpp08.html
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论