摘要: 1, 拷贝构造函数的参数必须是"const"和"引用"类型,特别是const,漏掉了会报错.g++的报错还强一点,clang的报错简直找不到边. 2,构造函数抛异常会导致析构函数不被执行. 阅读全文
posted @ 2019-12-21 14:54 相印 阅读(180) 评论(1) 推荐(0)
摘要: https://www.jianshu.com/p/4bf4d1860588 阅读全文
posted @ 2019-12-21 13:15 相印 阅读(457) 评论(0) 推荐(0)
摘要: class A { public: int a; void showthis() { printf("from A,this:%p\n", this); } }; class B { public: int b; void infothis() { printf("from B,this:%p\n" 阅读全文
posted @ 2019-12-21 10:52 相印 阅读(250) 评论(0) 推荐(0)
摘要: You can: Derived(const Derived& d) : Base(d) { cout << "Derived::Derived(const B&)" << endl; } This calls the Base copy constructor on the Base sub-ob 阅读全文
posted @ 2019-12-21 10:02 相印 阅读(231) 评论(0) 推荐(0)
摘要: https://en.cppreference.com/w/cpp/language/using_declaration 在[Inheriting constructors]这一节. 其实叫做"基类的构造函数前置"比较好. 像mystring继承自string类,但仍然是提供字符串功能.new的时候 阅读全文
posted @ 2019-12-21 03:14 相印 阅读(1354) 评论(0) 推荐(0)