1
#include <iostream>
template <typename T1, typename T2>
class B{
public:
void update(){ std::cerr<<__PRETTY_FUNCTION__<<std::endl; }
void func1(){ std::cerr<<__PRETTY_FUNCTION__<<std::endl; }
void func2(){ std::cerr<<__PRETTY_FUNCTION__<<std::endl; }
};
template <typename T1>
class B<T1, int>{
public:
void update(){ std::cerr<<__PRETTY_FUNCTION__<<"(specialization)"<<std::endl;}
};
int main(){
B<int, double> b1;
b1.update();
b1.func1();
B<int, int> b2;
b2.update();
//b2.func1();//there's no function 'func1' in B<int,int>
}
私は、特定のテンプレートパラメータ(データ型)用update
機能を特化したいです。部分特殊
私はtemplate class B
を特化しようとしましたが、メンバー全体の機能を再度実装する必要があるようです。
他のメンバーは特殊化間で正確に同じであるため、メンバー全体を再実装するのは面倒です。
この場合の回避策はありますか?
[C++テンプレート部分的な特殊メンバ関数]の可能な重複(http://stackoverflow.com/questions/15374841/c-template -partial-specialization-member-function) – LogicStuff