decltype

Started by
1 comment, last by iMalc 10 years, 10 months ago

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


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

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

This topic is closed to new replies.

Advertisement