I writing application using c++ and Qt. I have a problem with building application.
I get many error but everything refers to static variable and undefined function.
I don't redefine static in any place of my code.
lastid.h code:
#ifndef LASTID_H
#define LASTID_H
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
class LastId
{
private:
static int customerLastId;
static int itemLastId;
public:
static void Init(vector<string> data)
{
customerLastId = atoi(data[0].c_str());
itemLastId = atoi(data[1].c_str());
}
/**
* Function incrementing lastid of customer
*/
static void incrementCustomerLastId()
{
customerLastId++;
}
/**
* Function incrementing lastid of item
*/
static void incrementItemLastId()
{
itemLastId++;
}
/**
* Function returning value of customer last id
*/
static int getCustomerLastId()
{
return customerLastId;
}
/**
* Function returning value of item last id
*/
static int getItemLastId()
{
return itemLastId;
}
};
int LastId::customerLastId = 0;
int LastId::itemLastId = 0;
#endif // LASTID_H
In class customer where i using it:
void Customer::init()
{
LastId::incrementCustomerLastId();
id = LastId::getCustomerLastId();
}
Second type of error is undefined function. Using the function getRecord i want to return object of type T with vector as a parameter of constructor. In each class with i use in this function i have a constructor with this format.
getRecord function:
template <typename T>
T Database::getRecord(string line)
{
vector<string> conversion;
int pos = 0;
string temp;
while ((pos = line.find(delimiter)) != string::npos) {
temp = line.substr(0, pos);
conversion.push_back(temp);
line.erase(0, pos + 1);
}
conversion.push_back(line);
T record(conversion);
conversion.clear();
conversion.shrink_to_fit();
return record;
}
sample class constructor definition
Customer(vector<string> data);
sample calling code
Database dbLoadCustomers("../data/customers.csv", 0);
vector<Customer> customers = dbLoadCustomers.getRecords<Customer>();
dbLoadCustomers.~Database();
Error list: error static redefinition