up/downcast with shared_ptr?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • .rhavin grobert

    up/downcast with shared_ptr?

    guess you have the following:

    class AA;
    class A {
    shared_ptr<AAm_ a;
    };

    class BB: public AA;
    class B {
    shared_ptr<BBm_ 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?
  • Noah Roberts

    #2
    Re: up/downcast with shared_ptr?

    ..rhavin grobert wrote:
    guess you have the following:
    >
    class AA;
    class A {
    shared_ptr<AAm_ a;
    };
    >
    class BB: public AA;
    class B {
    shared_ptr<BBm_ 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.

    Comment

    Working...