up/downcast with shared_ptr?

R

.rhavin grobert

guess you have the following:

class AA;
class A {
shared_ptr<AA> m_a;
};

class BB: public AA;
class B {
shared_ptr<BB> m_a;
};

void g(B* pB);

void f(A* pA) { <-- called with a B*
// i need to call g() here //
};

what would be the best way to do this?
 
N

Noah Roberts

..rhavin grobert said:
guess you have the following:

class AA;
class A {
shared_ptr<AA> m_a;
};

class BB: public AA;
class B {
shared_ptr<BB> m_a;
};

void g(B* pB);

void f(A* pA) { <-- called with a B*
// i need to call g() here //
};

what would be the best way to do this?

You're working with raw pointers here, not the shared_ptr. Do it like
you normally would.

If you where working with shared_ptrs you would use the pointer casts
documented in the boost documentation.
 

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,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top