Boost logo

Boost Users :

From: Delfin Rojas (drojas_at_[hidden])
Date: 2005-04-29 21:20:55


Hello all,

I hope somebody can help me with this. What I want to do is the following:

Let's say I have a templated class called Foo

template<class U>
class Foo
{
public:
        Foo(U * p) : m_p(p) {}
        ~Foo() {}
        U* getP() const { return m_p; }
private:
        U* m_p;
};

Now let's say I want to have a collection of pointers to Foo. What should I
do? The possibilities I can think of are the following:

1) Create a class FooBase and have Foo inherit from FooBase. FooBase is
non-templated so there should be no problem with having a collection of
pointers to FooBase where I can put instances of Foo. The problem with this
approach is that given a FooBase* in that collection I could not use the
getP method because I would not know what type of Foo it holds.

2) Create a boost::variant of all the possible types of Foo<U>* I want to
have. Then have a collection of this FooVariant. Using static visitation I
can obtain the original type of Foo<U>* in a given FooVariant. The problem
with this approach is that I get an ICE from VC++ 7.1 when the type of U
gets too complex (shared_ptr to another type for example).

Have I overlooked something? Is there a better technique for what I want to
achieve? Any help would be great,

Thanks

Delfin Rojas


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