Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;错误:与调用不匹配<;类构造函数(char*&;,char*&;,char*&;,char*&;)_C++_Mysql_Class_Vector_Constructor - Fatal编程技术网

C++ C++;错误:与调用不匹配<;类构造函数(char*&;,char*&;,char*&;,char*&;)

C++ C++;错误:与调用不匹配<;类构造函数(char*&;,char*&;,char*&;,char*&;),c++,mysql,class,vector,constructor,C++,Mysql,Class,Vector,Constructor,我试图用这个程序做的是,我有一个MySQL结果表,我正在遍历这些行。每行有5列,我想将每个字段存储到类的私有数据成员中。一旦我有了这个类,我想把这个类推回到类类型的向量中。因此,在main.cpp中,我有: Wine wines("None", 0, 0, 0, "None"); 它应该调用此构造函数: Wine::Wine(string inputName, int inputVintage, int inputRating, int inputScore, string inputType

我试图用这个程序做的是,我有一个MySQL结果表,我正在遍历这些行。每行有5列,我想将每个字段存储到类的私有数据成员中。一旦我有了这个类,我想把这个类推回到类类型的向量中。因此,在main.cpp中,我有:

Wine wines("None", 0, 0, 0, "None");
它应该调用此构造函数:

Wine::Wine(string inputName, int inputVintage, int inputRating, int inputScore, string inputType) {
   name = inputName;
   vintage = inputVintage;
   rating = inputRating;
   score = inputScore;
   type = inputType;
}
回到正题:

    vector<Wine> wineVector;
    res = mysql_perform_query(conn, (char*)cmd.str().c_str()); //cmd is just a ostringstream holding the query.
    loadResultsToVector(wines, wineVector, res);
有什么想法吗?

这是错误的:

Wine w,
// ...
w(row[0], row[1], row[2], row[3], row[4]);
编译器认为您想要在
w
对象上调用
operator()
,或者
w
是一个函数。我想您需要调用
Wine
上的构造函数并初始化
w
参数:

w = Wine(row[0], row[1], row[2], row[3], row[4]);
但是为什么要把
w
设为函数参数呢。这:
winew(行[0],行[1],行[2],行[3],行[4])应该足够了


另一个问题是,构造函数需要不同的参数。它的签名是:
string,int,int,int,string
,而不是四个
char*
。因此,您需要进行转换。

错误消息非常清楚。阅读错误消息。编译器专门为您发出错误消息。在调用函数之前将整数转换为C样式字符串,或者更改参数的参数类型。哦,这很有趣,但它解决了我的问题,所以谢谢!我还考虑了使用atoi和atof的类型转换。
Wine w,
// ...
w(row[0], row[1], row[2], row[3], row[4]);
w = Wine(row[0], row[1], row[2], row[3], row[4]);