4
この例では、2番目の関数をどのように呼び出すことができますか?C++でテンプレート以外の関数もある場合、特殊なテンプレート関数を呼び出す
template<class T>
T square(T a) {
std::cout << "using generic version to square " << a << std::endl;
return a*a;
}
/// "int" is so special -- provide a specialized function template
template<>
int square(int a) {
std::cout << "using specialized generic version to square " << a << std::endl;
return a*a;
}
/// and there's one more: a non-template square function for int
int square(int a) {
std::cout << "using explicit version to square " << a << std::endl;
return a*a;
}
ありがとうございます!
[なぜ関数テンプレートを特化しませんか?](http://www.gotw.ca/publications/mill17.htm) – BoBTFish
あなたは何を意味するのか分かりませんが、私の質問は実際のコードではあまり意味がないかもしれません。私はそれがどのように可能かと思っていただけです。 – user2343039