shared_ptr and containers

G

Gonsolo

Hi!

I try to do the following:

class A {
};

class B : public A {

};

int main()
{
vector< shared_ptr<A> > v;
shared_ptr<B> d( new B );
v.push_back( d );
shared_ptr<B> d2 = dynamic_pointer_cast( v[0] );
}

and the compiler (g++) bails out with an:

error: no matching function for call to
'dynamic_pointer_cast(boost::shared_ptr<A>&)'


Is dynamic_pointer_cast supposed to work with containers like vector?

Thanks.
 
G

Gonsolo

Found out myself;

(...)
dynamic_pointer_cast<B>
(...)

instead of

(...)
dynamic_pointer_cast
(...)

did it.
Also, I had to add a virtual destructor in "A" to make it polymorphic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top