Jump to content

  • Log In with Google      Sign In   
  • Create Account


Decltype and template help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 taliesinnz   Members   -  Reputation: 231

Like
0Likes
Like

Posted 23 November 2010 - 09:59 PM

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

Sponsor:

#2 u   Members   -  Reputation: 211

Like
0Likes
Like

Posted 23 November 2010 - 10:38 PM

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.

#3 Chris_F   Members   -  Reputation: 2180

Like
0Likes
Like

Posted 24 November 2010 - 12:02 AM

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.

#4 taliesinnz   Members   -  Reputation: 231

Like
0Likes
Like

Posted 24 November 2010 - 06:21 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS