たとえば、次のコードがあります。
template <class T>
void g(T b){
;
}
template <class T>
void h(T b){
;
}
class T{
method X;
method Y;
method Z; //many methods but the implementation of the methods are different from TT
};
class TT{
method X;
method Y;
method Z; //the implementation of the methods are different from T
}
void f(){
if(a==1){
T b; //use type T to define b
} else{
TT b; //use type TT to define b
}
g(b);
h(b);
i(b);// I need to use b for many different functions.
}
また、変数 b のスコープが関数 f にある必要があります。
クラス T と TT には多くのメソッドがありますが、メソッドの実装は異なります。
助言がありますか?