简体   繁体   English

C ++ Push_back类型有多个

[英]c++ Push_back type with multiple

I have the following C++ Code... 我有以下C ++代码...

struct myType
{
    int SID;
    int IID;
    std::string myString;
};

std::vector<myType[2]> _type;

The problem is when i do this... 问题是当我这样做时...

for (int x = 1; x < 82432; x++)
{
    _type.push_back(myType());
}

it give me the following error 它给我以下错误

Error   441 error C2664: 'void std::vector<myType [2],std::allocator<_Ty>>::push_back(const myType (&)[2])' : cannot convert argument 1 from 'myType' to 'myType (&&)[2]'

The idea was to create a vector array like so: _type[82431][2].SID <<= type 想法是创建一个像这样的向量数组:_type [82431] [2] .SID << = type

Any help appreciated! 任何帮助表示赞赏!

You cannot create vector of array type, one of the reason is that you cannot assign one array to other, the closes you can get is: 您无法创建数组类型的向量,原因之一是您无法将一个数组分配给其他数组,您可以获得的关闭次数是:

std::vector<std::array<myType, 2>> _type;

This is also not right 这也不对

for (int x = 1; x < 82432; x++)
{
    _type.push_back(myType());
}

even if you could create vector of arrays, in your loop you are pushing data of type myType while your vector is of type myType[2] . 即使您可以创建数组的向量,在循环中您myType推送类型为myType数据,而向量必须为myType[2]类型。 So to make it work with std::array change to _type.push_back({myType(), myType()}); 因此,要使其与std::array更改为_type.push_back({myType(), myType()});

see here http://coliru.stacked-crooked.com/a/b77015b21524de77 for some other uses 参见此处http://coliru.stacked-crooked.com/a/b77015b21524de77用于其他用途

由于某些愚蠢的原因...我可以做到这一点!

myType _type[82432][2];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM