以下のコードは2つのデフォルトのパラメータを持つ2つのFooテンプレートを示しています.Foo1は別々のプロトタイプを持ち、Foo2はそうでなければ同じです。テンプレートの2つのデフォルトパラメータ。ここで何が間違っていますか?
Foo1への最初の呼び出しで、コンパイラ(VS2010 Native C++)がエラーを生成するのはなぜですか?
#include <limits>
// not needed but to prevent answers in this direction...
#undef max
#undef min
template< typename T >
void Foo1(T v1 = std::numeric_limits<T>::min(), T v2 = std::numeric_limits<T>::max());
template< typename T >
inline
void Foo1(T v1, T v2)
{
// ...
}
template< typename T >
inline
void Foo2(T v1 = std::numeric_limits<T>::min(), T v2 = std::numeric_limits<T>::max())
{
// ...
}
int main()
{
Foo1<int>(0); /* Will cause error C2589: '::' : illegal token on right side of '::' */
Foo1<int>(0, 10);
Foo2<int>(0);
Foo2<int>(0, 10);
}
私は ''メイン()を提供するために、あなたのポストを編集しました。それ以外の良い質問、+1。 –