I have a class cashier
which has 3 attributres : ID , Password ,tries with the standard GET & SET method
//Header file
#ifndef CASHIER_H
#define CASHIER_H
#include <string>
using namespace std;
class cashier
{
public:
cashier();
cashier(const cashier& orig);
virtual ~cashier();
void setID(string);
string getID();
void setPassword(string);
string getPassword();
void settries(int);
int gettries();
private:
string ID;
string Password;
int tries;
};
#endif /* CASHIER_H */
cashier.cpp file
#include "cashier.h"
cashier::cashier()
{
}
cashier::cashier(const cashier& orig)
{
}
cashier::~cashier()
{
}
void cashier::setID(string value)
{
this->ID = value;
}
void cashier::setPassword(string value)
{
this->Password = value;
}
string cashier::getID()
{
return this->ID;
}
string cashier::getPassword()
{
return this->Password;
}
void cashier::settries(int value)
{
this->tries=value;
}
int cashier::gettries()
{
return this->tries;
}
In my main file , I am attempting to read from a text file and store the values inside cashier c and push it into my vector cashier_all
#include <iostream>
#include "cashier.h"
#include <fstream>
#include <vector>
int main()
{
fstream afile;
char rubbish[100];
afile.open("cashier.txt",ios::in);
afile.getline(rubbish,100); //read in first line
vector <cashier> cashier_all;
cashier c;
string temp_id;
string temp_password;
int temp_tries;
while(afile>>temp_id)
{
afile>>temp_password;
afile>>temp_tries;
c.setID(temp_id);
c.setPassword(temp_password);
c.settries(temp_tries);
cashier_all.push_back(c); //c is not being pushed into the vector
// for some unknown reason
}
vector<cashier>::iterator v1;
vector<cashier>::iterator v2;
v1 = cashier_all.begin();
v2 = cashier_all.end();
while (v1 != v2)
{
cout<<v1->getID()
<<endl
<<v1->getPassword()
<<endl
<<v1->gettries();
v1++;
}
system("PAUSE");
}
cashier.txt
CashierID password tries
001 def 0
002 ghi 0
003 jkl 0
Checking my debugger , the error is at the cashier_all.pushback where it is not pushing c into the vector cashier_all , You can try for yourself if you dont believe me
EDIT : It works after i remove all the constructors
i dont understand why copy constructor would affect the pushing of cashier into cashier_all , can someone explain to me ??