Errors C2785 and C2912 for explicit specialization of function template with trait return type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The following code gives VC++ 7.1 compiler errors C2785 and C2912

template<class U> struct Trait {typedef double result;}
template<class T> typename Trait<T>::result foo()
template<> typename Trait<int>::result foo<int>(); // Line causes errors

Shouldn't this code compile correctly? If so, is Microsoft aware of this bug

Bill Rubin
 
The following code gives VC++ 7.1 compiler errors C2785 and C2912:
template<class U> struct Trait {typedef double result;};
template<class T> typename Trait<T>::result foo();
template<> typename Trait<int>::result foo<int>(); // Line causes errors.

Shouldn't this code compile correctly? If so, is Microsoft aware of this bug?

Bill,

FWIW, the Comeau compiler warns that your code should be:

template<class U> struct Trait {typedef double result;};
template<class T> typename Trait<T>::result foo();
template<> Trait<int>::result foo<int>();

Although VC7.1 still has a problem with this code, the Whidbey alpha
compiler doesn't object to it (with or without the typename present).

.... so it looks like MS have fixed this for the next version of the
compiler.

Dave
 
Back
Top