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
This has nothing to do with std::vector
and non-default constructors.
You did not provide the whole code, but I assume this is the continuation of the previous question.
Your Controls::operator=
is invalid, it creates copies of QWidgets
, and puts them into brand new QLayout
. Controls
object that you pass to push_back
is temporary object that is destroyed after the call and it's copy is put into vector. But destroyed object's QWidget
members are put into QLayout
, which is not destroyed and which is added to the widget you try to show (Panel
). After temporary Controls
object is destroyed, Panel->show()
calls Panel's QLayout
methods that try to access already deleted widgets.
Do you really need to save copies of your Controls
objects in your vector? If you store pointers, that would get rid of your problem. Why do you need that vector at all?
And once again, do not use auto_ptr
, it's deprecated and you don't need it to correctly manage deletion of QObjects
.