i have following problem.
i have class c has template function f3 defined below.
template <class t> void c::f3(t *obj) { //.......some code... obj->f1(); }
i have 2 classes d1 , d2. d1 has funcion d1::f1 , d2 has function d2::f1. these not polymorphic(not virtual functions.). d1 , d2 derived class b contains common function b::f2.
void b::f2(c *obj) { //..........some code...... c->f3(this); } void d1::f2(c *obj) { b::f2(obj); } void d2::f2(c *obj) { b::f2(obj); }
as mentioned, f1 not polymorphic.
now suppose have following code.
void myfunction(c *obj) { d1 *d1 = new d1(); d1->f2(obj); /*the following call sequence. d1::f2 b::f2 c::f3 //template function instatiated c::f3(b *), whereas required c::f3(d1*) b::f1 //desired call d1::f1 }
is there clean way of instantiating c::f3(d1*) above. 1 way copy code of b::f2 d1::f2. want avoid duplicating code. other solution using polymorphism, in case using template instantiation not serve purpose.