推回静态向量<对<字符串,双精度[9]> > myVector;
Push back to a static vector< pair<string, double[9]> > myVector;
我想存储大量信息,其中包含1个字符串和9个双精度。这些信息将属于一个"项目",所以我想按名称排序,因此我决定将其放入一个成对的向量中,成对的第一部分是名称,第二部分是双数组。因此,我可以很容易地对其进行排序,也可以很轻松地访问它们。
我有一个带有静态私有数据成员"myVector"的C++类
代码如下:
class MyClass : public OtherClass{
private:
static vector< pair<string, double[9]> > myVector;
public:
MyClass(void);
~MyClass(void);
};
vector< pair<string, double[9]> > MyClass::myVector;
问题是,在这个类的.cpp中,当我尝试执行以下操作时:
myVector.push_back(make_pair(sName, dNumericData));
其中sName是字符串类型的变量,dNumericData是双数组大小为9的变量,我得到一个错误:
2 IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=std::pair<std::string, double [9]>, _Alloc=std::allocator<std::pair<std::string, double [9]>>]" matches the argument list
argument types are: (std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, double *>)
object type is: std::vector<std::pair<std::string, double [9]>, std::allocator<std::pair<std::string, double [9]>>>
你知道我该怎么做吗?
dNumericData
衰减为指针,因此参数类型不匹配。您可以将std::array<>
同时用于对类型和dNumericData
。
我会制作一个结构或类,而不是使用std::pair:
struct MyStuff {
string name;
array<double, 9> values; // use float unless you need so much precision
MyStuff(string name_, array<double, 9> values_) : name(name_), values(values_) {}
};
vector<MyStuff> v;
v.emplace_back(MyStuff("Jenny", {{8,6,7,5,3,0,9}}));
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 是numeric_limits&lt; int&gt; :: is_modulo从逻辑上矛盾
- opencv 2.4.7在iOS错误背景_segm.hpp #include&lt; list&gt;未找到
- 在修改列表后,std :: list&lt; t&gt; :: end()的值是否会更改
- ///<评论></评论>在Visual Studio中