我想要存储的信息数量将包含一个字符串,9个双倍。这个信息将属于一个“项”,所以我想按名称进行排序,因此我决定将其放入成对的向量中,其中第一部分是名称,第二部分是一个双重数组。因此,我可以很容易地分类,并轻松地访问他们。
我有一个C++类,其静态私有数据成员"myVector“
代码如下所示:
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]>>>知道我该怎么做吗?
发布于 2014-04-13 14:17:34
dNumericData衰变为指针,因此参数类型不匹配。您可以将std::array<>用于对类型和dNumericData。
发布于 2014-04-13 14:24:11
我将创建一个结构或类,而不是使用std::偶数:
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}}));https://stackoverflow.com/questions/23043742
复制相似问题