我有一个带有“float2, unsigned int”-pair 模板的向量,例如:
std::vector<std::pair<float2, unsigned int>> myVec;
然后我试图将这样一对添加到向量中:
unsigned int j = 0;
float2 ab = {1.0, 2.0};
myVec.push_back(std::make_pair(ab, j));
这就是我期望它应该如何工作,但是当我尝试编译它时,我得到了错误:
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**
将此数据类型添加到我的对持有向量的正确方法是什么?
float2 类型定义为:
typedef float float2[2];