I have a base structure FooBase
:
struct FooBase { };
Then I create a template structure Foo
which is a child of FooBase
:
template <typename typeName> struct Foo : public FooBase { typeName* foo };
In some class I create a vector of FooBase
and add instances of Foo
in it:
vector <FooBase> FooVector
...
Foo <Bar> fooInstance;
fooInstance.foo = new Bar();
FooVector.push_back ( fooInstance );
Then I needed to access the stored data, but I'm getting predictable and obvious error about an absence of the member foo
in FooBase
FooVector[0].foo
I can not write something like
Foo <Bar> fooInstance = FooVector[0]
since I don't know the template parameter.
How do I store instances of Foo
in the vector so I can access them later. Note, that I don't know the template parameter at the last step - when reading data from the vector.
P.S. NO BOOST ALLOWED!
Bar
bytypename
? Do you need to do anything withBar
that is specific to it's type (my guess would be no).