以下に3つのプロトタイプがあります。最初のもの (コメントアウト) が機能することを期待していましたが、機能しないのはこれだけです (エラーについては、コード内のコメントを参照してください)。私にとってさらに驚くべきことは、両方が存在する場合でも、次の 2 つのいずれかが機能することです。
/////////////////////////////////////////////////
// Prototypes:
/////////////////////////////////////////////////
// Causes "ambiguous call to overloaded function" at the call site when when one or both
// of the below prototypes is also present. Otherwise causes unresolves external
//template<typename T> void func();
// Okay, can have this one AND/OR the below declaration
template<typename T> typename std::enable_if<std::is_integral<T>::value, void>::type func();
// Also okay, can have this one AND/OR the above declaration
template<typename T> typename std::enable_if<std::is_integral<T>::value, void>::type func();
int main()
{
func<int>();
}
/////////////////////////////////////////////////
// Definitions:
/////////////////////////////////////////////////
template<typename T> typename std::enable_if<std::is_integral<T>::value, void>::type func() {}
template<typename T> typename std::enable_if<!std::is_integral<T>::value, void>::type func() {}
正しいプロトタイプはどれですか?最初のプロトタイプが機能しないのはなぜですか? 私はVS2010とVS2012を使用しています