When compiling the code below, I get the following error:
welcome.h:110:38: error: no matching function for call to 'Mesazhi::Mesazhi(int&, std::string&, int&, Mesazhi&, int&)'
I have included the class file and the main file. Please check the code below.
#include <ctime>
#include <iostream>
#include <list>
#include <fstream>
#include <stack>
using namespace std;
#ifndef _welcome_H
#define _welcome_H
class Mesazhi {
int id;
string pershkrimi;
int dita;
int muaji;
int viti;
public:
Mesazhi (int ID, string p){
id=ID; pershkrimi=p;
datasot();
}
Mesazhi (int ID, string p, int d, int m, int v){
id=ID; pershkrimi=p; dita=d; muaji=m; viti=v;
}
void datasot(){
time_t t=time(0);
struct tm* tani=localtime(& t);
viti=tani->tm_year + 1900;
muaji=tani->tm_mon+1;
dita=tani->tm_mday;
}
int getDita() const {
return dita;
}
void setDita(int dita) {
this->dita = dita;
}
int getId() const {
return id;
}
void setId(int id) {
this->id = id;
}
int getMuaji() const {
return muaji;
}
void setMuaji(int muaji) {
this->muaji = muaji;
}
string getPershkrimi() const {
return pershkrimi;
}
void setPershkrimi(string pershkrimi) {
this->pershkrimi = pershkrimi;
}
int getViti() const {
return viti;
}
void setViti(int viti) {
this->viti = viti;
}
};
class Menaxhim {
list <Mesazhi> lista;
stack <Mesazhi> mesazhet;
public:
Menaxhim (){
futje_dhena();
}
void futje_dhena(){
int id; string p;
while(!cin.eof()){
cout<<"fusni mesazhet"<<endl;
cin>>id>>p;
Mesazhi njemesazh(id, p);
lista.push_back(njemesazh);
}
}
void shkrim_file(){
fstream file("c:\\data\\mesazhet.txt");
if(file.is_open()){
list <Mesazhi>::iterator it;
for(it=lista.begin(); it!=lista.end(); it++){
file<<it->getId()<<" "<<it->getPershkrimi()<<endl;
}
}else
cout<<"file ka probleme me shkrimin";
}
void lexim() {
int id; string p; int d; int m; int v;
fstream file("c:\\data\\mesazhet.txt");
while(!file.eof()){
file>>id>>p>>d>>m>>v;
Mesazhi m (id, p, d, m, v);
mesazhet.push(m);
}
}
void afishim(){
list<Mesazhi>::iterator it=lista.begin();
for(;it!=lista.end();it++){
cout<<it->GetId()<<" "<<it->getPershkrimi()<<endl;
cout<<mesazhet.top().GetId()<<" "<<mesazhet.top().getPershkrimi()<<" "<<mesazhet.top().getDita()
<<" "<<mesazhet.top().getMuaji()<<" "<<mesazhet.top().getViti() <<endl;
}
}
};
#endif /* _welcome_H */
#include "welcome.h"
int main() {
Menaxhim mesazhet;
mesazhet.shkrim_file();
mesazhet.lexim();
mesazhet.afishim();
return 0;
}
while (!cin.eof())is not correct, ifeofhappens then you will process one garbage entry. Also you will have an infinite loop if reading an int fails. Instead, check if the read succeeds or not. Same for all the otherwhile...eofloops.