B
Benedikt Weber
I found the following compiler error with Microsoft Visual C++ .NET.
I use different functions with return types determined by a Traits class.
Function g() below works ok, but when I put the two declarations f1() and
f2(), the compiler gets disturbed. The error message does not even reproduce
the original code correctly. When the two declarations are switched, the
problem goes away.
Benedikt
//----------------------------------------
#include "stdafx.h"
template<class S,class T> struct Traits;
template<>
struct Traits<double,double>
{
typedef double RType;
};
template<class T> class Matrix
{
public: typedef T Type;
};
template<class U, class V>
Matrix<typename Traits<typename U::Type,typename V::Type>::RType>
f1(const U& mat1, const V& mat2);
template<class U, class V>
Matrix<typename Traits<typename U::Type,V>::RType>
f2(const U& mat1, const Matrix<V>& mat2);
template<class U, class V>
Matrix<typename Traits<typename U::Type,typename V::Type>::RType>
g(const U& mat1, const V& mat2)
{
return Matrix<U::Type>();
}
int _tmain(int argc, _TCHAR* argv[])
{
Matrix<double> A;
Matrix<double> B;
g(A,B);
/*
error C2893: Failed to specialize function template
'Matrix<Traits<U::Type,V>::RType> g(const U &,const V &)'
Notice how the template argument has changed from
Traits<typename U::Type,typename V::Type>
to
Traits<U::Type,V>
There is no problem if the declarations of f1 and f2 change order!!
*/
return 0;
}
I use different functions with return types determined by a Traits class.
Function g() below works ok, but when I put the two declarations f1() and
f2(), the compiler gets disturbed. The error message does not even reproduce
the original code correctly. When the two declarations are switched, the
problem goes away.
Benedikt
//----------------------------------------
#include "stdafx.h"
template<class S,class T> struct Traits;
template<>
struct Traits<double,double>
{
typedef double RType;
};
template<class T> class Matrix
{
public: typedef T Type;
};
template<class U, class V>
Matrix<typename Traits<typename U::Type,typename V::Type>::RType>
f1(const U& mat1, const V& mat2);
template<class U, class V>
Matrix<typename Traits<typename U::Type,V>::RType>
f2(const U& mat1, const Matrix<V>& mat2);
template<class U, class V>
Matrix<typename Traits<typename U::Type,typename V::Type>::RType>
g(const U& mat1, const V& mat2)
{
return Matrix<U::Type>();
}
int _tmain(int argc, _TCHAR* argv[])
{
Matrix<double> A;
Matrix<double> B;
g(A,B);
/*
error C2893: Failed to specialize function template
'Matrix<Traits<U::Type,V>::RType> g(const U &,const V &)'
Notice how the template argument has changed from
Traits<typename U::Type,typename V::Type>
to
Traits<U::Type,V>
There is no problem if the declarations of f1 and f2 change order!!
*/
return 0;
}