vector::push_back not work for non default constructor

后端 未结 4 1140
萌比男神i
萌比男神i 2021-01-28 13:26

i have a Controls class that have default constructor and copy constructor and other constructor ,and an assignment operator , and i want to create array of my cla

4条回答
  •  情深已故
    2021-01-28 14:05

    When using auto_ptr you should use release not get to pass the pointer to new owner:

    Not this in Controls::Controls(QLayout &Parent , string name , const int &Default_value):

    Layout.addWidget(Label.get() , 0 , 0);
    

    But that:

    Layout.addWidget(Label.release() , 0 , 0);
    

    Otherwise - your auto_ptr are deleting the pointers at the end of scope of this constructor.

提交回复
热议问题