摘要: C++拾遗 更新一些平时遇到的小细节: 1.关于类的无参构造函数和带有全部默认参考值的构造函数的区别 书上说的是带有全部默认值的构造函数就是无参构造函数,私以为不以为然,来看下边这个例子: 1 #include <iostream> 2 using namespace std; 3 class A 阅读全文
posted @ 2016-03-05 18:51 CRAZY_HENRY 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 三、多层继承的派生类 1.多层继承的派生类只需在构造函数的初始化列表中写出直接基类的构造函数即可 1 class student 2 { 3 public: 4 student(int n, string nam) 5 { 6 num = n; name = nam; 7 } 8 }; 9 clas 阅读全文
posted @ 2016-03-05 13:38 CRAZY_HENRY 阅读(2705) 评论(0) 推荐(0) 编辑
摘要: 二、有内嵌对象的派生类 1.一般来说,我们会这样定义构造函数 student( int i, string nam, int pid, string pnam, int sid) : person( i, nam),parent(pid,pnam){ stuid = sid; } person是基类 阅读全文
posted @ 2016-03-03 21:40 CRAZY_HENRY 阅读(768) 评论(0) 推荐(0) 编辑
摘要: 一、简单派生类的构造函数 1.所谓简单派生类,就是指派生类中不包含基类的内嵌对象的派生类。 2.一般来说,这样的派生类的构造函数的形式是: student( int i, string nam, int sid) : person( i, nam) { stuid = sid; } person(是 阅读全文
posted @ 2016-03-03 20:28 CRAZY_HENRY 阅读(493) 评论(1) 推荐(0) 编辑
摘要: 1 #include <iostream> 2 using namespace std; 3 class A 4 { 5 public: 6 A(){ cout << "调用A无参" << endl; } 7 A(int a){ dataA = a; cout << "调用A有参" << endl; 阅读全文
posted @ 2016-03-03 19:30 CRAZY_HENRY 阅读(6595) 评论(0) 推荐(1) 编辑