. - , , , , , .
++ - - , .
new . , . , .
( & ), , , , .
, , (.. ::std::vector<SubElement *> c), , new. ( ) . "" . , .
(.. ::std::vector<SubElement> c), c.push_back(SubElement()), . , . , , , .
There is a way to get a container to take control of pointers, but only indirectly. You can have copies of objects that you take over in the container. For this, ordinary class people are used ::std::tr1::shared_ptr<T>. Your container declaration would look like this: ::std::vector< ::std::tr1::shared_ptr<SubElement> > c. Then you can: c.push_back(new SubElement());and the container will remove the SubElement objects when this is done.
You have to read shared_ptrand really understand what it does before using it, though.
source
share