| | |
No matching function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 10
Reputation:
Solved Threads: 0
Hi
I’m getting compile errors in the following code:
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:
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
I’m getting compile errors in the following code:
C++ Syntax (Toggle Plain Text)
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; } }
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)
//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
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
Isn'T it obvious?
istream and ifstream are not the same.
So the compiler does not know a proper constructor.
ifstream infile("data", ios::in); string name, surname; while (infile >> surname) { infile >> name; Person temp(infile);
Person(std::istream&);So the compiler does not know a proper constructor.
バルサミコ酢やっぱいらへんで
![]() |
Similar Threads
- print function not working (C++)
- no matching function for call to 'strcmp(std::string&, std::string&)' (C++)
- Qt4 and devcpp (C)
- passing a vector to a function? :errors: (C++)
- Reading from external data file (C++)
- need help, fingerprint verification system (C)
- passing objects as arguments (C++)
Other Threads in the C++ Forum
- Previous Thread: passing `const' as `this' argument of `' discards qualifiers
- Next Thread: No appropriate default constructor?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






