Decltype and template help

Started by
2 comments, last by taliesinnz 13 years, 5 months ago
I am using MSVC2010 and getting a strange error

struct Foo;template< typename T>class Bar{}template<>class Bar<  Foo >{     int returnsomething()     {           return 1;     }}template< typename T>auto getsomething() -> decltype( Bar< T >::returnsomething ) {   Bar< T > t;   return t.returnsomething();}main(){   cout << getsomething< Foo >() << endl;}

MSVC gives me an error C2893: Failed to specialize function template ''unknown-type'

I have read the help but not sure what it mean to my code.

Can someone enlighten me? Thanks
Advertisement
Tried this on my GCC, got this:
test.cc:30:32: error: invalid use of non-static member function 'int Bar<Foo>::returnsomething()'test.cc:30:32: error: no matching function for call to 'getsomething()'

Changed this line:
auto getsomething() -> decltype( Bar< T >::returnsomething )
to:
auto getsomething() -> decltype( Bar< T >().returnsomething() )

and it compiles fine. Proper error message FTW.
Wow, and here I was under the impression that GCC had horrible compiler errors, especially when it came to templates. Just another reason why I wish I used GCC instead of MSVC.
Quote:Original post by u
Tried this on my GCC, got this:
test.cc:30:32: error: invalid use of non-static member function 'int Bar<Foo>::returnsomething()'test.cc:30:32: error: no matching function for call to 'getsomething()'

Changed this line:
auto getsomething() -> decltype( Bar< T >::returnsomething )
to:
auto getsomething() -> decltype( Bar< T >().returnsomething() )

and it compiles fine. Proper error message FTW.


Yay! It is now working on MSVC too. I guess more brackets the better.

Thanks

This topic is closed to new replies.

Advertisement