E
er
i have
class Impl; //abstract
class Impl_Aublic Impl{...};//abstract
class Impl_Bublic Impl{...};//abstract
class Impl_A_0: public Impl_A{/* implements */};
class S{ public: S(Impl*,...); ...};
class S_A: public S{ public: S_A(Impl_A* impl,...):S(impl){};
class S_B: public S{ public: S_B(Impl_B* impl,...):S(impl){};
//hierarchy ends here
template<typename T,typename U>
std::vector<U> mult(T* pimpl){
//calls U(pimpl,...);
};
a) std::vector<S_A> vec(mult<Impl_A0*,S_A>(Impl_A0*)); //ok
b) std::vector<S_A> vec(mult(Impl_A0*)); //compiler error: no
matching function
i would have thought that T and U are implicitly specified by the
input and return type, respectively, so that b) would work?
Overloading like this does not work because i loose information about
the leaf class (Impl_A0* in example):
std::vector<S_A> mult_A(Impl_A* pimpl){return mult(pimpl);}
std::vector<S_B> mult_A(Impl_B* pimpl){return mult(pimpl);}
any suggestion?
class Impl; //abstract
class Impl_Aublic Impl{...};//abstract
class Impl_Bublic Impl{...};//abstract
class Impl_A_0: public Impl_A{/* implements */};
class S{ public: S(Impl*,...); ...};
class S_A: public S{ public: S_A(Impl_A* impl,...):S(impl){};
class S_B: public S{ public: S_B(Impl_B* impl,...):S(impl){};
//hierarchy ends here
template<typename T,typename U>
std::vector<U> mult(T* pimpl){
//calls U(pimpl,...);
};
a) std::vector<S_A> vec(mult<Impl_A0*,S_A>(Impl_A0*)); //ok
b) std::vector<S_A> vec(mult(Impl_A0*)); //compiler error: no
matching function
i would have thought that T and U are implicitly specified by the
input and return type, respectively, so that b) would work?
Overloading like this does not work because i loose information about
the leaf class (Impl_A0* in example):
std::vector<S_A> mult_A(Impl_A* pimpl){return mult(pimpl);}
std::vector<S_B> mult_A(Impl_B* pimpl){return mult(pimpl);}
any suggestion?