Boost logo

Boost Users :

From: Brad Ryder (bradryder67_at_[hidden])
Date: 2007-09-07 14:19:38


Greetings,

This is my first post to the boost users list and I am a relative new
comer to this wonderful template library, so have some mercy on me.

I am sure this question has been asked before and I tried to find it
via google without any luck.

If someone could show me how to make the following polymorphism work
so that AddChild of class A will add type B and type C class I would
really appreciate it. I don't want to have to typecast in this
situation, but I can't see any other way. Please forgive me if this
is a basic question, but I am new to some of these concepts.

Kind regards

Brad

typedef boost::shared_ptr<A> shPtrA;
typedef boost::shared_ptr<B> shPtrB;
typedef boost::shared_ptr<C> shPtrC;

class A
{

void AddChild(shPtrA& child);
private:
std::vector<shPtrA> m_children;
}

class B : public A
{

}

class C: public B
{

}

main()
{
A base;
shPtrB spB(new B());
shPtrC spC(new C());

// I dont want to typecast spB or spC

A.AddChild( (shPtrA) spB);
A.AddChild( (shPtrA) spC);
}


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