lym*_*yml 8 c++ templates boost tuples g++
在尝试移植一些代码以在linux中编译时,我得到了特殊的编译错误.通过代码库搜索,我终于设法将其归结为以下代码.
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
Run Code Online (Sandbox Code Playgroud)
试着用它我得到错误:
test.cpp: In function <functionName>:
test.cpp:8: error: expected primary-expression before ‘)’ token
Run Code Online (Sandbox Code Playgroud)
代码在Visual Studio中工作正常但由于某种原因我无法弄清楚为什么它不适用于g ++.这里的任何人都知道如何解决这个问题?
Jam*_*lis 17
你需要一些template
爱:
return t.template get<0>();
Run Code Online (Sandbox Code Playgroud)
Visual C++不能正确解析模板,这就是为什么它错误地接受没有template
关键字的代码.有关template
此处需要的原因的详细信息,请参阅Stack Overflow C++ FAQ "我在哪里以及为什么必须在依赖名称上放置"template"和"typename"?"