1

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;
    }
1
  • while (!cin.eof()) is not correct, if eof happens 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 other while...eof loops. Commented Jun 10, 2014 at 23:15

1 Answer 1

4

Here

Mesazhi m (id, p, d, m, v);

you want to construct a new Mesazhi with a non default constructor that you didn't declare neither implement.

This because you have

int m;
while(!file.eof()) {
  Mesazhi m(...);
}

so your inner m declaration shadows the outside one, m is considered of type Mezashi, not int anymore. You should rename it to something different, eg

Mesazhi mesazhi(id,p,d,m,v);

That's a reason why criptic variable names can cause problems: you don't even realize you are using them. GCC supports the warning -Wshadow that helps finding these kind of issues.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.