vector::push_back not work for non default constructor

后端 未结 4 1110
萌比男神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:14

    I'm not sure that you are implementing your copy semantics correctly, and the use of std::auto_ptr as a data member is kind of an "alert sign".

    Are your Controls really deep-copyable?

    Maybe you should just use scoped_ptr instead of auto_ptr data members, ban copy declaring private copy constructor and private operator=, and use vector> ?

    (Or use C++11 and move semantics, and so use unique_ptr instead of auto_ptr, and just use compiler automatically generated move operations?)

提交回复
热议问题