On Jan 25, 3:53*pm, Jarek Blakarz <jumia...@gmail.com> wrote:
>
> I'm trying to compile the following program.
> It does not compile.
> Unfortunately I don't understand the compile error messages.
which one?
> Please help me understanding what's going wrong and give
> me some indications of how to fix it.
> * vector<auto_ptr<X> > vecXP;
> * auto_ptr<X> xPtr(new X);
> * vecXP . push_back(xPtr);
> * auto_ptr<auto_ptr<X> > elem = vecXP[0]; * // compiler error
auto_ptr has a destructive copy constructor and assignment operator
which is something that the standard containers have trouble dealing
with. Don't ever try to put an auto_ptr into a container. It just
won't work. Also, stop using auto_ptr altogether. As of C++11, it's
deprecated. Its replacement (unique_ptr) is much better behaved.
Cheers!
|