的std :: make_pair使用float阵列(FLOAT2,无符号整型) [英] std::make_pair with float array (float2, unsigned int)

查看:516
本文介绍了的std :: make_pair使用float阵列(FLOAT2,无符号整型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个'模板FLOAT2一个向量,无符号int',对这样的:

 的std ::矢量<的std ::对< FLOAT2,无符号整型>> myVec;

然后我想这样一对添加到载体:

  unsigned int类型J = 0;
FLOAT2 AB = {1.0,2.0};
myVec.push_back(性病:: make_pair(AB,J));

这是我期望它应该工作,但是当我尝试编译我的错误:

  1> C:\\ Program Files文件(x86)的\\微软的Visual Studio 10.0 \\ VC \\包括\\实用程序(163):错误C2536:'的std :: _ Pair_base< _Ty1,_Ty2> ::性病:: _ Pair_base< _Ty1,_Ty2> ::第一:不能指定数组初始化明确
1>同
1> [
1> _Ty1 = FLOAT2,
1> _Ty2 =无符号整型
1> ]
1> C:\\ Program Files文件(x86)的\\微软的Visual Studio 10.0 \\ VC \\ \\包括公用事业(166):看的声明的std :: _ Pair_base< _Ty1,_Ty2> ::第一
1>同
1> [
1> _Ty1 = FLOAT2,
1> _Ty2 =无符号整型
1> ]
1> C:\\ Program Files文件(x86)的\\微软的Visual Studio 10.0 \\ VC \\包括\\实用程序(247):见参考函数模板实例化'的std :: _ Pair_base< _Ty1,_Ty2> :: _ Pair_base<浮动(安培;)[2 ],无符号​​整型和放大器;>(_其他1,_Other2)正在编制
1>同
1> [
1> _Ty1 = FLOAT2,
1> _Ty2 =为unsigned int,
1> _Other1 =浮子(安培)[2],
1> _Other2 = unsigned int类型和放大器;
1> ]
1> myTest.cpp(257):见参考函数模板实例化'的std ::对< _Ty1,_Ty2> ::对< FLOAT2(安培),无符号整型和放大器;>(_其他1,_Other2)正在编制
1>同
1> [
1> _Ty1 = FLOAT2,
1> _Ty2 =为unsigned int,
1> _Other1 = FLOAT2(安培),
1> _Other2 = unsigned int类型和放大器;
1> ] **文强**

什么是这种数据类型添加到我的一对保持载体的正确方法是什么?

的FLOAT2类型定义为:

 的typedef浮动FLOAT2 [2];


解决方案

C ++数组衰变为指针几乎每次使用。更改 FLOAT2

 的typedef的std ::阵列<浮动,2  - ; FLOAT2;

或者,如果你没有C ++ 11然而,你可以使用的boost ::阵列

I have a vector templated with a 'float2, unsigned int'-pair like:

std::vector<std::pair<float2, unsigned int>> myVec;

And then I'm trying to add such a pair to the vector:

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

This is how I expect it should work, though when I try to compile it I get the error:

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**

What is the correct way to add this data type to my pair holding vector?

The float2 type is defined as:

typedef float        float2[2];

解决方案

C++ arrays decay to pointers on almost every use. Change float2:

typedef std::array<float, 2> float2;

Or, if you don't have C++11 yet, you can use boost::array.

这篇关于的std :: make_pair使用float阵列(FLOAT2,无符号整型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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