boost::shared_ptr assignment
I'm having problems assigning a boost::shared_ptr. The following code doesn't compile for me - what am i doing wrong. I have a base class, Foo which is extended to Boo and Zoo:
class Foo{
public:
Foo() {}
virtual ~Foo() {}
virtual void do_something() {/*..*/}
};
class Boo : public Foo{
public:
Boo () {}
virtual ~Boo () {}
virtual void do_something() {/*..*/}
};
class Zoo : public Foo {
public:
Zoo () {}
virtual ~Zoo () {}
virtual void do_something() {/*..*/}
};
At runtime I want to assign a Boo or Zoo pointer to my shared_ptr:
int main()
{
shared_ptr<Foo> pf;
if (...) {
pf = new Boo;
} else {
pf = new Zoo;
}
pf->do_something();
}
Note that I do NOT want to assign the shared_ptr at construction, i.e. using pf(new Foo) - I need to the assignment until runtime.
Thanks for your help.

