本文介绍了如何从课程中获取getInt *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个类 Stockauto ,带有构造函数 Stockauto(int,date *,double,car *,int)。 日期和 car 是我在 Stockauto 。在创建DAO时,我需要使用 res-> getInt(),.... 。 我总是得到错误:无法将int转换为日期*。有人知道如何解决这个问题吗? 在我的数据库中有3张桌子 Stockauto ,日期和汽车;在 Stockauto 中使用来自 date 和 cars 的外键。 vector< Stockauto *> StockautosDAO :: getAll() { ResultSet * res = NULL; Statement * stmt = NULL; vector< Stockauto *> stockautos; 尝试 { if (con == NULL || con> isClosed()) con = DatabaseSingleton :: getInstance() - > getConnection(); if (con == NULL) return stockautos; stmt = con - >的createStatement(); res = stmt - > executeQuery( SELECT * FROM Stockauto); while (res - > next()) { // nummer is de volgorde Stockauto * stockauto = new Stockauto( res-> getInt( 1 ),res-> getInt( 2 ),res-> getDouble( 3 ),res-> getString( 4 ),res-> getInt( 5 )); stockautos.push_back(stockauto); } stmt-> close(); delete stmt; delete res; con - > close(); } catch (SQLException& e) { cout<< 问题:<< e.what()<< endl; con - > close(); if (stmt!= NULL) delete stmt; if (res!= NULL) delete res; } return stockautos; } 错误: c:\ usersrs \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\ dev-branch-driesvandevelde \ cardealer\cardealer \stockauto'sdao.cpp(62):错误C2664:'Stockauto :: Stockauto(int,Datum *,double,Auto *,int)':无法转换参数2从'int32_t'到'Datum *'从积分类型转换为指针类型需要reinterpret_cast,C风格的转换或函数式转换 解决方案 检查此行: Stockauto * stockauto = new Stockauto(res-> getInt(1),res-> getInt( 2),res-> getDouble(3),res-> getString(4),res-> getInt(5)); 正如Richard指出的那样, res-> getInt(2)返回 int ,并且 Stockauto 构造函数需要一个 Datum * 。 所以这不是正确的构造函数,或者你的参数错了。 I have a class Stockauto with a constructor Stockauto(int, date*,double,car*,int).Date and car are 2 other objects I use in Stockauto. When creating a DAO I need to use res->getInt(),.....I always get the error: cannot convert int to date*.Does someone know how I can fix this?In my database there are 3 tables Stockauto, date and cars; with a foreign key from date and cars in Stockauto.vector<Stockauto*> StockautosDAO::getAll(){ ResultSet *res = NULL; Statement *stmt = NULL; vector<Stockauto*> stockautos; try { if(con == NULL ||con->isClosed()) con = DatabaseSingleton::getInstance()->getConnection(); if (con==NULL) return stockautos; stmt = con -> createStatement(); res = stmt -> executeQuery ("SELECT * FROM Stockauto"); while (res -> next()) { //nummer is de volgorde Stockauto* stockauto = new Stockauto(res->getInt(1),res->getInt(2), res->getDouble(3), res->getString(4), res->getInt(5)); stockautos.push_back(stockauto); } stmt->close(); delete stmt; delete res; con ->close(); } catch (SQLException &e) { cout<<"PROBLEM: "<<e.what()<<endl; con ->close(); if(stmt != NULL) delete stmt; if(res != NULL) delete res; } return stockautos;}Error:c:\users\dries\desktop\software project\groep 4\dev-branch-driesvandevelde\cardealer\cardealer\stockauto'sdao.cpp(62): error C2664: 'Stockauto::Stockauto(int,Datum *,double,Auto *,int)' : cannot convert parameter 2 from 'int32_t' to 'Datum *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast 解决方案 Check this line:Stockauto* stockauto = new Stockauto(res->getInt(1),res->getInt(2), res->getDouble(3), res->getString(4), res->getInt(5));As Richard pointed out, res->getInt(2) returns an int, and the Stockauto constructor expects a Datum*.So either this is not the correct constructor, or your parameter is wrong. 这篇关于如何从课程中获取getInt *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 05:34