vector中存储的对象在clear时,会调用对象的析构函数

来源:互联网 发布:win10如何更改mac地址 编辑:程序博客网 时间:2024/06/07 12:51
class Text1{public:    Text1(){        cout << "Text" <<endl;    }    ~Text1(){        cout << "~Text" <<endl;    }    Text1(const Text1& other){        cout << "copy 构造" << endl;    }    Text1& operator = (const Text1& other){        cout << "赋值" << endl;        return *this;    }};vector<Text1> v;Text1 t1;v.push_back(t1);v.clear();cout<<"vvv"<<endl;/* Text copy 构造 ~Text vvv ~Text */

总结:push_back对象的时候,会调用拷贝构造函数




0 0
原创粉丝点击