Приветствую.
Ниже код.
Первые три вызова функций компилируются нормально, четвертый не компилируется с ошибкой.
MSVS 2008.
Не могу разобраться... поясните, пожалуйста, почему.
class A
{
public:
typedef int TY;
};
template <class Y>
class X
{
public:
Y m_y;
};
template<class T, size_t N>
bool test(T & t, X<typename T::TY> (&x)[N])
{
return true;
}
template<class T, size_t N>
bool test2(T & t, X<T> (&x)[N])
{
return true;
}
template<class T>
bool test3(T & t, X<typename T::TY> * x)
{
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
A a;
X<A::TY> x[2];
X<A> x2[2];
test<A>(a, x); // OK
test2(a, x2); // OK
test3(a, x); // OK
test(a, x); // error C2784: 'bool test(T &,X<T::TY> (&)[N])' : could not deduce template argument for 'X<T::TY> (&)[N]' from 'X<Y> [2]'
return 0;
}
Статистика:
— MSVS 2010 выдает ту же ошибку.
— Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) компилирует без ошибок
— g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 компилирует без ошибок