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

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
 
D

David Lowndes

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top