While trying to port some code to compile in linux I get peculiar compilation errors. Searching through the codebase I finally manage to get it down to the following code.
5: // include and using statements
6: template<typename RT, typename T1>
7: RT func(tuple<T1> const& t) {
8: return t.get<0>();
9: }
10: // test code
Trying to use it I get the error:
test.cpp: In function <functionName>:
test.cpp:8: error: expected primary-expression before ‘)’ token
The code works fine in Visual Studio but for some reason I can't figure out why it doesn't work with g++. Anyone here got a clue how on how to work around this?
You need some template
love:
return t.template get<0>();
Visual C++ does not parse templates correctly, which is why it incorrectly accepts the code without the template
keyword. For more information on why the template
is required here, see the Stack Overflow C++ FAQ "Where and why do I have to put “template” and “typename” on dependent names?"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With