944,098 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3270
  • C++ RSS
Aug 31st, 2006
0

No matching function

Expand Post »
Hi

I’m getting compile errors in the following code:

C++ Syntax (Toggle Plain Text)
  1. void Driver::read_data()
  2. {
  3. ifstream infile("data", ios::in);
  4. string name, surname;
  5.  
  6. while (infile >> surname) {
  7. infile >> name;
  8. Person temp(infile);
  9. temp.read_surname(infile);
  10. temp.read_name(infile);
  11. temp.read_phone(infile);
  12. temp.read_age(infile);
  13. temp.read_weight(infile);
  14. 87 person_map[surname][name] = temp;
  15. }
  16. }
The errors tell me that

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

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

Here’s what my Person class looks like:

C++ Syntax (Toggle Plain Text)
  1. //Person class declaration
  2. class Person {
  3. public:
  4. std::istream& read_surname(std::istream&);
  5. std::istream& read_name(std::istream&);
  6. std::istream& read_phone(std::istream&);
  7. std::istream& read_age(std::istream&);
  8. std::istream& read_weight(std::istream&);
  9. std::string& read_phone(std::string&);
  10. int& read_age(int&);
  11. double& read_weight(double&);
  12. std::string get_name() const { return name; }
  13. std::string get_surname() const { return surname; }
  14. std::string get_phone() const { return phone; }
  15. int get_age() const { return age; }
  16. double get_weight() const { return weight; }
  17. Person(std::string&, std::string&, std::string&, int&, double&);
  18. Person(std::istream&);
  19. private:
  20. std::string surname;
  21. std::string name;
  22. std::string phone;
  23. int age;
  24. double weight;
  25. };
  26. #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:erson()'
person_header.h:11: note: candidates are: Person:erson(const Person&)
person_header.h:27: note: Person:erson(std::istream&)
person_header.h:26: note: Person:erson(std::string&, std::string&, std::string&, int&, double&)

Thanx guys
Similar Threads
Reputation Points: 19
Solved Threads: 0
Newbie Poster
V1RuZ is offline Offline
10 posts
since Aug 2006
Aug 31st, 2006
0

Re: No matching function

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.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Aug 31st, 2006
0

Re: No matching function

Thanx again WolfPack!

Isn'T it IT?
Reputation Points: 19
Solved Threads: 0
Newbie Poster
V1RuZ is offline Offline
10 posts
since Aug 2006
Aug 31st, 2006
0

Re: No matching function

huh? Isn't it what?
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: passing `const' as `this' argument of `' discards qualifiers
Next Thread in C++ Forum Timeline: No appropriate default constructor?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC