我有以下程序名为 DBAccess.h
#ifndef DBAccess1_HH
#define DBAccess1_HH
#include <iostream>
#include <sqlite3.h>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
struct InOut_Schedular_Settings
{
string inout_ID;
string inout_FromTime;
string inout_ToTime;
string inout_InOutMode;
};
class sqliteDB {
public:
int rc;
char *zErrMsg;
sqlite3 *db;
const char *sql;
sqlite3_stmt * stmt;
const char* InOut_Schedular_Settings(const char* buffer1,const char* buffer2, const char* buffer3)
{
//====SOME CODE TO ACCESS SQLITE DATABASE====//
}
231 list<InOut_Schedular_Settings> GET_InOut_Schedular_Settings(const char* buffer1)
232 {
238 list<InOut_Schedular_Settings> InOut_Schedular_Settings_list;
int rc = sqlite3_open("/DBsqlite3/empdbv3.db", &db);
sql = "SELECT * FROM InOutTimeM WHERE ID= @ID;";
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, 0);
int Code_x1 = sqlite3_bind_parameter_index(stmt, "@ID");
if(sqlite3_step(stmt)==SQLITE_ROW) {
int column = sqlite3_column_count(stmt);
for(int i = 0; i < column; i++)
{
std::string A = std::string(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
std::string B = std::string(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
std::string C = std::string(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
std::string D = std::string(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3)));
288 InOut_Schedular_Settings info; //Creating list object "info"
289 info.inout_ID = A;
290 info.inout_FromTime = B;
291 info.inout_ToTime = C;
292 info.inout_InOutMode = D;
294 cout<<"Preparing to push data into List"<<endl;
295 InOut_Schedular_Settings_list.push_back(info);
cout<<"Data was pushed successfully"<<endl;
}
}
else {
cout<<"\nERROR while fetching record from the InOutTimeM table[ " << sqlite3_errmsg(db) << " ]" << endl;
}
sqlite3_finalize(stmt);
sqlite3_close(db);
return InOut_Schedular_Settings_list;
}
我调用此DBAccess.h的程序如下 main.cpp
#include <iostream>
#include <sqlite3.h>
#include <stdlib.h>
#include <list>
#include <iterator>
#include <algorithm>
#include <cstring>
#include <unistd.h>
#include <string>
#include <cstdio>
#include <sstream>
#include <cctype>
#include <cstdlib>
#include "DBAccess.h"
using namespace std ;
int main()
{
sqliteDB object1;
const char* value1= "2";
object1.GET_InOut_Schedular_Settings(value1);
cout << "\n\nAll the statement were executed properly\n\n";
return 0;
}
编译时的程序会出现以下错误:
DBAccess.h:231:30: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::list’
list<InOut_Schedular_Settings> GET_InOut_Schedular_Settings(const char* buffer1)
^
DBAccess.h:231:30: error: expected a type, got ‘sqliteDB::InOut_Schedular_Settings’
DBAccess.h:231:30: error: template argument 2 is invalid
DBAccess.h: In member function ‘int sqliteDB::GET_InOut_Schedular_Settings(const char*)’:
DBAccess.h:238:31: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::list’
list<InOut_Schedular_Settings> InOut_Schedular_Settings_list;
^
DBAccess.h:238:31: error: expected a type, got ‘sqliteDB::InOut_Schedular_Settings’
DBAccess.h:238:31: error: template argument 2 is invalid
DBAccess.h:238:62: error: invalid type in declaration before ‘;’ token
list<InOut_Schedular_Settings> InOut_Schedular_Settings_list;
^
DBAccess.h:288:29: error: expected ‘;’ before ‘info’
InOut_Schedular_Settings info; //Creating list object "info"
^
DBAccess.h:288:33: error: invalid use of non-static member function
InOut_Schedular_Settings info; //Creating list object "info"
^
DBAccess.h:289:4: error: ‘info’ was not declared in this scope
info.inout_ID = A;
^
DBAccess.h:295:34: error: request for member ‘push_back’ in ‘InOut_Schedular_Settings_list’, which is of non-class type ‘int’
InOut_Schedular_Settings_list.push_back(info);
我知道,我必须提供typename,并声明模板&lt;&gt ;.但不幸的是,我无法做到正确。如果你能提供帮助,我将非常感谢。谢谢。
注意:我知道在.h文件中定义一个函数本身就是不好的做法。我稍后会制作另一个.cpp文件。
答案 0 :(得分:0)
发布我自己问题的答案真的很愚蠢。我犯的错误实在太傻了。
如果您注意到功能 -
const char* InOut_Schedular_Settings
与我的列表名称相同:
231 list<InOut_Schedular_Settings>
238 list<InOut_Schedular_Settings> InOut_Schedular_Settings_list;
我所要做的就是更改函数名称:
const char* InOut_Schedular_Settings
到(别的)
const char* InOut_Schedular_Settings1
抱歉这么不耐烦。