Boost logo

Boost Users :

From: Josh S (aek_at_[hidden])
Date: 2006-05-20 02:27:47


I have a few newb questions:

I have the following classes

class Base {
   Base();
   virtual ~Base();
   virtual doStuff();
}

class Foo: public Base {
   doStuff();
}

class FooContainer {
   createFoos(int numOfFoos);
   Foo* getFoo(int indexToFoo);
   Destroy();
}

class BaseContainer {
        void addObj(boost::shared_ptr<Base> obj);
}

How do I cast the pointer returned from FooContainer::getFoo(), as
something I can pass to BaseContainer::addObj ?
Is this correct to do this? Assuming I cant change the implementation of
FooContainer or the BaseContainer interface. The BaseContainer interface
should not have a special case for adding Foo's.

Good practise tells me I shouldn't create a temporary either.

I do not want the shared_ptr in BaseContainer to call delete on Foo (I
will manually call FooContainer::Destroy()

----
Now, what happens if I instead want FooContainer to only be responsible 
for creating the Foo objects, and not be responsible for deleting them.
Instead I want the shared_ptr to call delete when the objects reference 
count reaches 0. How would that done?
Thanks in advance,
Josh S

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