Given this snippet:
template <std::size_t Index, typename T, typename ...Args>
typename type_at<Index, T, Args...>::type
get(T t1, Args... args)
{
return
static_cast<type_at<Index, T, Args...>::type>
(
reinterpret_cast<void*>
(
value_at<Index, T, Args...>::get(t1, args...)
)
);
}
int main()
{
int * a = new int(10);
double* b = new double(3.14);
std::string c = "But I'm a string :(";
std::cout<< *get<0>(a, b, &c) <<"\n";
std::cout<< *get<1>(a, b, &c) <<"\n";
std::cout<< *get<2>(a, b, &c) <<"\n";
}
that doesn't work on GCC 4.8.1 but compiles and runs fine in VS2012 with the Nov CTP compiler ( didn't try clang by the way )
Which compiler is right?
In this particular case GCC is more standard compliant as you are missing typename
when referring to a dependent type in type_at<Index, T, Args...>::type
part of your code.
Clang is also doing a similar thing and gives a nice error message (as always):
./test.cc:40:29: error: missing 'typename' prior to dependent type name 'type_at<Index, T, Args...>::type'
static_cast<type_at<Index, T, Args...>::type>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typename
1 error generated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.