模板函数错误(使用Boost.Tuples)
#include <list>
#include <boost/tuple/tuple.hpp>
template<class InputIterator>
void f(InputIterator it)
{
typedef boost::tuple<typename InputIterator::value_type, int> Pair;
std::list<Pair> paired;
typename std::list<Pair>::const_iterator output;
for(output=paired.begin(); output!=paired.end(); ++output)
{
output->get<1>();
}
}
我正在使用此模板功能获取库。 Gcc 4.1.2 (codepad.org) 报告以下错误:
In function 'void f(InputIterator)':
Line 12: error: expected primary-expression before ')' token
compilation terminated due to -Wfatal-errors.
能否有对模板更有经验的人提供建议?自己研究的问题或关键词?这让我陷入困境。
#include <list>
#include <boost/tuple/tuple.hpp>
template<class InputIterator>
void f(InputIterator it)
{
typedef boost::tuple<typename InputIterator::value_type, int> Pair;
std::list<Pair> paired;
typename std::list<Pair>::const_iterator output;
for(output=paired.begin(); output!=paired.end(); ++output)
{
output->get<1>();
}
}
I'm getting libraries with this template function. Gcc 4.1.2 (codepad.org) reports the following error:
In function 'void f(InputIterator)':
Line 12: error: expected primary-expression before ')' token
compilation terminated due to -Wfatal-errors.
Could someone more experienced with templates offer advice? Either the problem or key phrases to research myself? This has me stuck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
get
是一个函数模板,并且output
的类型取决于模板参数InputIterator
,因此您需要使用template< /code> 关键字:
Comeau C++ 模板常见问题解答 很好地描述了为什么会出现这种情况是必要的。
Because
get
is a function template and the type ofoutput
is dependent upon the template parameterInputIterator
, you need to use thetemplate
keyword:The Comeau C++ Template FAQ has a good description of why this is necessary.