Hi,
I have a template class, C_Foo<T>, which is specialised in a number of ways.
struct Bar_Base { ... };
struct Bar_1 : public Bar_Base { ... };
struct Bar_2 : public Bar_Base { ... };
struct Bar_3 : public Bar_Base { ... };
class C_Foo<T> { ... };
class C_Foo_1 : public C_Foo<Bar_1> { ... };
class C_Foo_2 : public C_Foo<Bar_2> { ... };
class C_Foo_3 : public C_Foo<Bar_3> { ... };
And instantiations as follows:
C_Foo_1 foo1;
C_Foo_2 foo2;
C_Foo_3 foo3;
I have a set of common operations, all of which are defined on C_Foo, that I want to perform on foo1, foo2, and foo3. I've tried the following:
vector<C_Foo *> v;
v.push_back(&foo1);
v.push_back(&foo2);
v.push_back(&foo3);
But I get compile errors, presumably because the compiler isn't sure how to go from a C_Foo_1 to a C_Foo.
Is it possible to do something like this? I want to be able to loop through foo1 .. fooN and perform the same operations on all of them, without having to copy and paste boilerplate code like so:
foo1.do_stuff();
foo2.do_stuff();
foo3.do_stuff();
Thanks for your help.