带浮点数组的std :: make_pair(float2,unsigned int)

Roy*_*rau 2 c++ arrays std-pair

我有一个用'float2,unsigned int'对模板化的向量,如:

std::vector<std::pair<float2, unsigned int>> myVec;
Run Code Online (Sandbox Code Playgroud)

然后我试图在向量中添加这样一对:

unsigned int j = 0;
float2 ab = {1.0, 2.0};
myVec.push_back(std::make_pair(ab, j));
Run Code Online (Sandbox Code Playgroud)

这是我期望它应该工作的方式,虽然当我尝试编译它时我得到错误:

1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2536: 'std::_Pair_base<_Ty1,_Ty2>::std::_Pair_base<_Ty1,_Ty2>::first' : cannot specify explicit initializer for arrays
1>          with
1>          [
1>              _Ty1=float2 ,
1>              _Ty2=unsigned int
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\utility(166) : see declaration of 'std::_Pair_base<_Ty1,_Ty2>::first'
1>          with
1>          [
1>              _Ty1=float2 ,
1>              _Ty2=unsigned int
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\utility(247) : see reference to function template instantiation 'std::_Pair_base<_Ty1,_Ty2>::_Pair_base<float(&)[2],unsigned int&>(_Other1,_Other2)' being compiled
1>          with
1>          [
1>              _Ty1=float2 ,
1>              _Ty2=unsigned int,
1>              _Other1=float (&)[2],
1>              _Other2=unsigned int &
1>          ]
1>          myTest.cpp(257) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<float2(&),unsigned int&>(_Other1,_Other2)' being compiled
1>          with
1>          [
1>              _Ty1=float2,
1>              _Ty2=unsigned int,
1>              _Other1=float2 (&),
1>              _Other2=unsigned int &
1>          ]**strong text**
Run Code Online (Sandbox Code Playgroud)

将此数据类型添加到我的对保持向量的正确方法是什么?

float2类型定义为:

typedef float        float2[2];
Run Code Online (Sandbox Code Playgroud)

Rei*_*ica 5

C++数组几乎在每次使用时都会衰减到指针.变化float2:

typedef std::array<float, 2> float2;
Run Code Online (Sandbox Code Playgroud)

或者,如果您还没有C++ 11,则可以使用boost::array.