i would appreciate help with the following problem: Please consider the code
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- template<typename T> struct A{};
- template<typename T> struct B: public A<T>{};
- template<typename T> void f(T obj){ cout << "default\n"; }
- template<typename T> void f(A<T> obj){ cout << "special case\n"; }
- int main(){
- A<int> a;
- f(a);
- B<int> b;
- f(b);
- }
Expand|Select|Wrap|Line Numbers
- special case
- default
What I would like to do, however, is specify function f for the special case that it is called with parameter of type A<T> or B<T> for any type T and any child B of A.
Is there a way to do this? Or do I have to write another template (with the same code) for the case f(B<T> obj)?
Any advise appreciated, I can't think of a good way.
~<><~~~~~~ presencia