#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.对模板更有经验的人能给出建议吗?要么是问题,要么是我要研究的关键短语?这让我卡住了。
发布于 2010-07-23 03:47:40
因为get是一个函数模板,并且output的类型取决于模板参数InputIterator,所以您需要使用template关键字:
output->template get<1>();Comeau C++ Template FAQ很好地描述了为什么这是必要的。
https://stackoverflow.com/questions/3312768
复制相似问题