小白学c++之effective c++条款12实现代码
来源:互联网 发布:淘宝比较有名的文玩店 编辑:程序博客网 时间:2024/05/16 01:44
class customer{public: customer(string s):name_(s){} customer(const customer & rhs):name_(rhs.name_) { cout<<"customer(const customer & rhs) run"<<endl; } customer& operator=(const customer & rhs) { name_=rhs.name_; cout<<"customer& operator=(const customer & rhs)"<<endl; return *this; } void print() const { cout<<name_<<endl; }protected: string name_;};class pcustomer:public customer{public: pcustomer(string s,int n):customer(s),p_(n){} pcustomer(const pcustomer& rhs): customer(rhs),p_(rhs.p_) { cout<<"pcustomer(const pcustomer& rhs run"<<endl; } pcustomer& operator=(const pcustomer& rhs) { cout<<" pcustomer& operator=(const pcustomer& rhs)"<<endl; customer::operator=(rhs); p_=rhs.p_; return *this; } void print() const { customer::print(); cout<<p_<<endl; }private: int p_;};int main(int argc, const char *argv[]){ // pcustomer p1("hello",0); // pcustomer p2("world",1); // pcustomer p3(p1); // p1=p2; // p3.print(); return 0;}注意base类里拷贝构造函数的调用
0 0
- 小白学c++之effective c++条款12实现代码
- Effective C++:条款01
- Effective C++:条款02
- Effective C++:条款03
- Effective C++:条款04
- Effective C++:条款05
- Effective C++:条款06
- Effective C++:条款07
- Effective C++:条款08
- 《effective C++》条款三
- 《effective C++》条款5
- 《effective C++》条款六
- Effective C++--经验条款
- Effective C ++ 条款34
- 《Effective C++》条款05
- 《Effective C++》条款06
- 《Effective C++》条款08
- Effective C++(条款5-12)
- Effective C++ 34
- codechef Fun with Rotation
- 一个开始
- KMP next[]小贴士
- hdu 2899 hdu 3400 三分/几何
- 小白学c++之effective c++条款12实现代码
- Win32 下 使用CMarkup类遇到的问题
- 面向对象的PHP(一):向类中增加新的public属性
- 【DP】 HDOJ 3516 Tree Construction
- 数据结构之线性表
- Ken Burns特效的幻灯片
- 给定一个正整数n,将其分成m段,每段为n1,n2,...,nm,求怎么划分使得n1*n2*...*nm最大
- 【LeetCode】【Python题解】Container with most water
- python中的字符映射