Jump to content

  • Log In with Google      Sign In   
  • Create Account


decltype


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
2 replies to this topic

#1 lride   Members   -  Reputation: 633

Like
0Likes
Like

Posted 26 May 2013 - 09:06 PM

I'm trying to make a convenient function template to retrieve different type of objects using tuple.


class Apple;
class Banana;
class Cherry;

typedef std::tuple<Apple, Banana, Cherry> Fruits;
Fruits fruits;

enum
{
  APPLE,
  BANANA,
  CHERRY
};


//When I try to use this, I get "Failed to specialize function template" error
template<std::size_t i>
decltype(std::get<i>(fruits)) getFruit()
{
   return std::get<i>(fruits)
}
ex) getFruit<APPLE>(); //error

 

 

 

 

 

 

 


 


Edited by lride, 26 May 2013 - 09:07 PM.

An invisible text.

Sponsor:

#2 Wooh   Members   -  Reputation: 611

Like
1Likes
Like

Posted 27 May 2013 - 12:13 AM

I think the class types that you use in the tuple has to be defined and not just forward declared.

#3 iMalc   Crossbones+   -  Reputation: 2299

Like
1Likes
Like

Posted 27 May 2013 - 12:33 AM

I think the class types that you use in the tuple has to be defined and not just forward declared.

Indeed. As per this page http://msdn.microsoft.com/en-us/library/s8kw2xcc.aspx "... make sure you can instantiate every type."


"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms




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