|
Boost Users : |
From: Brad Ryder (bradryder67_at_[hidden])
Date: 2007-09-07 20:29:05
On 9/7/07, Michael Fawcett <michael.fawcett_at_[hidden]> wrote:
> On 9/7/07, Brad Ryder <bradryder67_at_[hidden]> wrote:
> > Hi Michael,
> >
> > Thanks for the response. Your solution will indeed work, but the side
> > effect is that spB and spC only have access to methods available in
> > the base class. Imagine that B & C have unique methods that I want to
> > access in main like.
> >
> > main()
> > {
> >
> > A base;
> > shPtrB spB(new B());
> > shPtrC spC(new C());
> >
> > spB.PrintBrad(); // unique to B
> > spC.PrintMichael(); // unique to C
> >
> > // this will fail obviously, but how else can I get access to unique
> > methods in B & C
> > base.AddChild(spB);
> > base.AddChild(spC);
> > }
> >
> > Thanks for your help
>
> Try to remember not to top-post.
>
> Generally you should not need to know if the instances are indeed A,
> B, or C. If you did, why would you be storing them in a container of
> base class pointers?
>
> If you find you really need to perform the cast, look at
> boost::static_pointer_cast.
>
> --Michael Fawcett
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Micheal,
Sorry about the top post and thank you again for the response.
I guess I really need to know how and if it's possible to make the
base class A method
void AddChild( shPtrA& child); accept shPtrA , shPtrB and shPtrC .
You mentioned boost::static_pointer_cast. I will investigate.
Thanks again.
Brad
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net