无法推导模板参数 [英] Template argument cannot be deduced

查看:178
本文介绍了无法推导模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 std :: transform 将两个相等大小的向量合并成一对向量。

I'm trying to use std::transform to merge two equal size vectors into a vector of pairs.

int main()
{
    vector<string> names;
    // fill it with names    
    vector<int> nums;
    // fill it with numbers

    typedef pair<int,string> Pair_t;
    vector<Pair_t> pv;

    transform(nums.begin(), nums.end(),
              names.begin(), back_inserter(pv),
              make_pair<int,string>);
}

VC10给我:

'_OutIt std::transform(_InIt1,_InIt1,_InIt2,_OutIt,_Fn2)' : could not deduce template argument for '_OutIt' from 'std::back_insert_iterator<_Container>'
          with
          [
              _Container=std::vector<Pair_t>
          ]

那么为什么不能推导出模板参数呢?

So why can't the template argument be deduced? And how do I fix it?

推荐答案

这是由于当前版本的VC10中的一个错误, c $ c> make_pair 无法正确解析。

This is due to a bug in the current version of VC10 whereby the overload of make_pair cannot be resolved properly.

有关这个确切问题的讨论此处,以及使用C ++ 0x的解决方法lambda表达式,由VC10支持。

There is a discussion about this exact problem here, along with a workaround using a C++0x lambda expression, which is supported by VC10.

这篇关于无法推导模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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