c++ - Error: no match for call to '(Household) -
so have error me makes no sense. have tried nothing seems work, figured guys able me. first post on website way.
i working on program involves class called "household.cc, h" , test program.
this household.h (the code in question)
class household{ public: // default constructor household(std::string nme, std::string adrs, int peeps, int ncome); household(); household(std::string& nme, std::string& adrs, int& peeps, int& ncome);
this household.cc file in question
// constructors household::household(std::string nme, std::string adrs, int peeps, int ncome){ name = nme; address = adrs; numpeople = peeps; income = ncome; } household::household(std::string& nme, std::string& adrs, int& peeps, int& ncome){ name =nme; address = adrs; numpeople=peeps; income=ncome; } household::household(){ name = ""; address = ""; numpeople = 0; income =0; }
and test class code in question is:
household temp; string n; int i; cout<< "please enter name, press enter, income of house\n"; getline(cin, n); cin >> i; myward.removehouse(temp(n, n, i, i)); break;
the error message
error: no match call '(household) (std:string&, std::string&, int&, int&)'
i don't understand why happening because household constructor have of these parameters. may missing obvious not obvious me. first time have ever worked c++ also.
edit: removehouse , myward irrelevant in question, added temp code. problem code
temp(n,n,i,i)
thats error is.
thanks in advance!
you initialized default constructor temp object, later tried re-initialize another constructor.. that's problem.
household temp; <-- initialized default constructor string n; int i; cout<< "please enter name, press enter, income of house\n"; getline(cin, n); cin >> i; myward.removehouse(temp(n, n, i, i)); <-- re-initialize?? bad idea.. break;
do initialize object constructor want (the 4-arguments 1 suppose) , use object.
also: gcc being used , warns set of arguments, no resolution available.
something might work:
string n; int i; // initialize n , meaningful here household temp(n, n, i, i); cout<< "please enter name, press enter, income of house\n"; getline(cin, n); cin >> i; myward.removehouse(temp); break;
i know nothing of other functions , regarding program's behavior though.
Comments
Post a Comment