开发者

Error in template function (using 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>();
    }
}

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 befor开发者_如何学Pythone ')' 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.


Because get is a function template and the type of output is dependent upon the template parameter InputIterator, you need to use the template keyword:

output->template get<1>();

The Comeau C++ Template FAQ has a good description of why this is necessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜