Hi

I’m getting compile errors in the following code:

void Driver::read_data()
   {
        ifstream infile("data", ios::in);
        string name, surname;
        
        while (infile >> surname) {
            infile >> name;
            Person temp(infile);
            temp.read_surname(infile);
            temp.read_name(infile);
            temp.read_phone(infile);
            temp.read_age(infile);
            temp.read_weight(infile);
   87     person_map[surname][name] = temp;
        }    
   }

The errors tell me that

87 driver.cpp instantiated from here
339 stl_map.h no matching function for call to `Person::Person()'

and then it gives me a bunch of candidates. Where am I apparently calling this function?

Here’s what my Person class looks like:

//Person class declaration
   class Person {
   public:
          std::istream& read_surname(std::istream&);
          std::istream& read_name(std::istream&);
          std::istream& read_phone(std::istream&);
          std::istream& read_age(std::istream&);
          std::istream& read_weight(std::istream&);
          std::string& read_phone(std::string&);
          int& read_age(int&);
          double& read_weight(double&);
          std::string get_name() const { return name; }
          std::string get_surname() const { return surname; }
          std::string get_phone() const { return phone; }
          int get_age() const { return age; }
          double get_weight() const { return weight; }
          Person(std::string&, std::string&, std::string&, int&, double&);
          Person(std::istream&);
   private:
           std::string surname;
           std::string name;
           std::string phone;
           int age;
           double weight;
       };    
   #endif

I’m running Dev C++ on Windows XP(Service Pack 2)

Here’s a short extraction from my compiler log:

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Steven\Desktop\CTI\C++ Unit 3\Finished Project\Makefile.win" all
g++.exe -c driver.cpp -o driver.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

C:/Dev-Cpp/include/c++/3.4.2/bits/stl_map.h: In member function `_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = std::string, _Tp = Person, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, Person> >]':
driver.cpp:
87: instantiated from here
C:/Dev-Cpp/include/c++/3.4.2/bits/stl_map.h:
339: error: no matching function for call to `Person::Person()'
person_header.h:11: note: candidates are: Person::Person(const Person&)
person_header.h:27: note: Person::Person(std::istream&)
person_header.h:26: note: Person::Person(std::string&, std::string&, std::string&, int&, double&)

Thanx guys

Isn'T it obvious?

ifstream infile("data", ios::in);
        string name, surname;
        
        while (infile >> surname) {
            infile >> name;
             Person temp(infile);
Person(std::istream&);

istream and ifstream are not the same.
So the compiler does not know a proper constructor.

Thanx again WolfPack!

Isn'T it IT?

huh? Isn't it what?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.