摘要: 先调用基类构造函数,再调用派生类构造函数 123456789101112131415161718 classBase{public: Base() { cout << "Base()" << endl;}};classDerived : publicBase{public: Derived() { cout << "Derived()" << endl;}};intmain(){ Der... 阅读全文
posted @ 2013-07-23 16:04 helloweworld 阅读(1008) 评论(0) 推荐(0) 编辑
摘要: EFfective C++和More Effective C++中有讲解。“条款23: 必须返回一个对象时不要试图返回一个引用”“条款31: 千万不要返回局部对象的引用,也不要返回函数内部用new初始化的指针的引用”为什么要返回引用呢——为了实现链式操作。返回一个对象不行吗?为什么有时要返回引用呢?主要是为了实现链式操作。看一个例子就明白了:1234567891011121314151617181920MyString& MyString::operator =(constMyString &other) { /*if (this != &other) { size = 阅读全文
posted @ 2013-07-23 15:19 helloweworld 阅读(634) 评论(0) 推荐(0) 编辑