Thursday, 22 August 2013

Can I create an array of auto_ptr?

Can I create an array of auto_ptr?

I have a base class, which is inherited by multiple derived classes. i
want to create array of autopointer of baseClass pointer. when i
initialise those autopointer i get some compile time error, then i tried
to do like that way
std::auto_ptr<base>pbase[3];
std::auto_ptr<base> b1(new derived1());
std::auto_ptr<base> b2(new derived2());
std::suto_ptr<base> b3(new derived3());
pbase[0] = b1;
pbase[2] = b2;
pbase[3] = b3;
then i get memory leaks. i can't get why it happens, do we can't use array
with auto_ptr.

No comments:

Post a Comment