多くの質問が寄せられており、それらは私がここで質問しようとしているものと似ていますが、同じではないと思います.
テンプレート化されたクラスがあります:
namespace app {
template <typename T>
class MyCLass {
public:
void dosome();
void doother();
}
} /*ns*/
そして実装:
template <typename T>
app::MyClass<T>::dosome() {}
template <typename T>
app::MyClass<T>::doother() {}
char
テンプレート パラメーターとしてa が提供されるクラスのインスタンスがある場合、関数dosome()
がまったく異なる方法で動作するようにします。しかし、私はその関数が異なる動作をしたいだけで、他のすべては同じように動作する必要があります。
入力してみました:
template<>
app::MyCLass<char>::dosome() {
}
しかし、コンパイラは、別の名前空間で特殊化を作成しようとしていると教えてくれます。
したがって、次のようなコードがある場合:
app::MyCLass<int> a;
app::MyCLass<char> b;
a.dosome(); // This must call the generic template definition
b.dosome(); // This must call the specialization
a.doother(); // This must call the generic template definition
b.doother(); // This must call the generic template definition
他の質問では、人々がクラス全体のまったく異なる専門分野を作成しているのを見ました。しかし、単一のメソッドの特殊化のみが必要です。