emplace_back和VC ++沮丧 [英] emplace_back and VC++ frustration

查看:277
本文介绍了emplace_back和VC ++沮丧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2012,尝试这两个与默认编译器和Nov CTP编译器,下面显示我的问题:

  struct doesCompile 
{
int mA,mB,mC,mD,mE;

doesCompile(int a,int b,int c,int d,int e):mA(a),mB(b),mC(c),mD
{
}
};

struct doesNotCompile
{
int mA,mB,mC,mD,mE,mF;

doesNotCompile(int a,int b,int c,int d,int e,int f):mA(a),mB(b),mC (e),mF(f)
{
}
};


int _tmain(int argc,_TCHAR * argv [])
{
std :: vector< doesCompile> goodVec;
goodVec.emplace_back(1,2,3,4,5);

std :: vector< doesNotCompile> badVec;
badVec.emplace_back(1,2,3,4,5,6); // error C2660:'std :: vector< _Ty> :: emplace_back':function不接受6个参数

return 0;为什么看起来emplace_back最多有5个参数的上限?
}

?他们甚至在 http://blogs.msdn.com上说/b/vcblog/archive/2011/09/12/10209291.aspx ,它需要一个任意数量的参数。



有任何方式VS2012 November CTP 编译器支持可变参数模板,但是它们 em>标准库尚未在该版本中更新。应固定在VS2013RC。强烈建议升级,因为即使11月CTP包含很多错误。如果不可能,请使用Konrad Rudolph提及的宏。


I'm using Visual Studio 2012, trying this both with the default compiler and the Nov CTP compiler, and the following below shows my problem:

struct doesCompile
{
    int mA, mB, mC, mD, mE;

    doesCompile(int a, int b, int c, int d, int e) : mA(a), mB(b), mC(c), mD(d), mE(e)
    { 
    }
};

struct doesNotCompile
{
    int mA, mB, mC, mD, mE, mF;

    doesNotCompile(int a, int b, int c, int d, int e, int f) : mA(a), mB(b), mC(c), mD(d), mE(e), mF(f)
    { 
    }
};


int _tmain(int argc, _TCHAR* argv[])
{
    std::vector<doesCompile> goodVec;
    goodVec.emplace_back(1, 2, 3, 4, 5);

    std::vector<doesNotCompile> badVec;
    badVec.emplace_back(1, 2, 3, 4, 5, 6);  //  error C2660: 'std::vector<_Ty>::emplace_back' : function does not take 6 arguments

    return 0;
}

Why on earth does it seem emplace_back is capped at a maximum of 5 arguments?? They even say in http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx that it would take an arbitary amount of arguments..

Is there any way around this, using VS2012?

解决方案

The VS2012 November CTP compiler supports variadic templates, but their Standard Library was not yet updated in that release. Should be fixed in VS2013RC. An upgrade is strongly recommended, because even the November CTP contained a lot of bugs. If not possible, use the macro mentioned by Konrad Rudolph.

这篇关于emplace_back和VC ++沮丧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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