小白学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
原创粉丝点击