"stephen henry" <> wrote in message
news: om...
> I'm trying to create a vector of pointers to a class:
>
> For example:
>
> class CMb ...
>
> std::vector< CMb* > myvect(100);
>
> myvect[10] = new CMb();
>
> But this doesn't work. g++ just spews out a whole load of uninituitive
> errors around the assignment operation.
The following code sample compiles without problem:
#include <vector>
class CMb {};
int main()
{
std::vector< CMb* > myvect(100);
myvect[10] = new CMb;
}
What was the error you were encountering?
> So, have just read a post on this newsgroup from a few years ago, I'm
> trying to use an auto_ptr instead.
>
> so,
>
> std::vector< std::auto_ptr<CMb> > myvect(100);
> myvect[10] = new CMb();
>
> But, this time the compiler complains that passing const
> std::auto_ptr<CMb> discards a qualifier.
It is illegal to use a container of std::auto_ptr
(because instances of auto_ptr cannot properly be copied).
You could use another smart pointer instead, however,
such as boost::shared_ptr (from
www.boost.org), which
will be adopted in the next revision of the standard.
hth,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form