There are two classes A and B, where A is the base class and B is the derived class:
template <typename T>
class A {T a;};
template <typename T>
class B: public A <T> {T b;};
and the following class representing a modified container
template <typename Item>
struct TItems {typedef std::vector <Item> Type;};
template <typename Item>
class ModCont
{
private:
typename TItems <Item>::Type items;
};
A function test() has pointer to container of A objects as formal parameter:
template <typename T>
void test ( ModCont <A <T> > *it) {}
I would like to apply polymorphism and pass container of B to the method test:
int main(int argc, char* argv[])
{
ModCont < A <double> > a_items;
ModCont < B <double> > b_items;
test (&a_items); //Works
test (&b_items); //Does not work
return 0;
}
The only way I found is to templatize a parameter of the test() method in this way:
template <typename Object>
void test ( ModCont <Object> *it) {}
Is there any way how to use the the "function" polymorphism instead of the compile polymorphism (templates?)
Thanks for your help...