VS2005 list template with own types

  • Thread starter Thread starter Arka
  • Start date Start date
A

Arka

Hi,

I am trying to migrate a VS2003 VC++ Solution to VS2005.

I found a problem with the list template !

I declared my list like this:

class MyOwnTypeList : public list<MyOwnType::Ptr>

where MyOwnType::Ptr is declared like this:

class MyOwnType
{
public:
typedef Pointer<MyOwnType> Ptr;
....
}

The compiler makes an error on:

push_back( bst );

where bst is:

MyOwnType::Ptr &bst

The error is:

error C2664: 'std::allocator<_Ty>::construct' : cannot convert
parameter 1 from 'MyOwnType *' to 'Pointer<T> *'

I must add that like another post in this group the Pointer class has
an overloaded '&' operator!

What is wrong ???

Can someone help me ???
 
Arka said:
Hi,

I am trying to migrate a VS2003 VC++ Solution to VS2005.

I found a problem with the list template !

I declared my list like this:

class MyOwnTypeList : public list<MyOwnType::Ptr>

where MyOwnType::Ptr is declared like this:

class MyOwnType
{
public:
typedef Pointer<MyOwnType> Ptr;
...
}

The compiler makes an error on:

push_back( bst );

where bst is:

MyOwnType::Ptr &bst

The error is:

error C2664: 'std::allocator<_Ty>::construct' : cannot convert
parameter 1 from 'MyOwnType *' to 'Pointer<T> *'

I must add that like another post in this group the Pointer class has
an overloaded '&' operator!

What is wrong ???

Can someone help me ???

Your Pointer<MyOwnType> doesn't meet the requirements on elements to be
stored in standard containers. In particular, it isn't
"copyconstructible". This requires (among other things) that taking the
address of an element returns the address of the element directly.

In general, avoid overloading operator&.

Tom
 
Arka said:
Hi,

I am trying to migrate a VS2003 VC++ Solution to VS2005.

I found a problem with the list template !

I declared my list like this:

class MyOwnTypeList : public list<MyOwnType::Ptr>
To complete Tom's answer, it is generally a bad idea to inherit from a std
container (among other things because they do not have virtual destructors).

You'd probably better use something like :
typedef std::list<boost::shared_ptr<MyOwnType> > MyOwnTypeList;

Arnaud
 
Back
Top