为什么不使用boost ::元组的工作。获得在模板函数在GCC? [英] Why doesn't using boost::tuple's .get work in template functions in gcc?

查看:102
本文介绍了为什么不使用boost ::元组的工作。获得在模板函数在GCC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图端口一些code在Linux编译我得到特殊的编译错误。通过codeBase的我终于搜索管理得到它归结为以下code。

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

在code工作在Visual Studio的罚款,但由于某种原因,我想不通为什么它不使用g ++工作。有人在这里得到了一个线索如何就如何解决此问题?

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?

推荐答案

您需要一些模板爱情:

return t.template get<0>();

的Visual C ++不能正确分析模板,这就是为什么它错误地接受了code,而不模板关键字。对于为什么这里需要的模板的更多信息,请参阅堆栈溢出的C ++ FAQ <一个href=\"http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-template-and-typename-on-dependent-names\">\"Where为什么我必须把模板和类型名称对因名字?

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?"

这篇关于为什么不使用boost ::元组的工作。获得在模板函数在GCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆