-
some help here.
Code:
int main ()
{
int Choise;
cout <<"Welcome! "<< endl;
string loser ="";
employee *Eptr = new workman (loser,loser,0,0);
return 0;
}
compiles and runs fine.
Code:
int main ()
{ int Choise;
cout <<"Welcome! "<< endl;
employee *Eptr = new workman ("","",0,0);
return 0;
}
does not compile and gives error:
"main.cpp": E2285 Could not find a match for 'workman::workman(char *,char *,int,int)' in function main() at line 31
why the ........ does this not compile!? it is like? the same thing annyway!
workman (string &fname,string &lname,int hours, double salary); => workman constructor
employee ( string &, string &, int = 0 , double = 0 ); => employee constructor
-
"" is a char*; string("") is a string. Use this
Code:
employee *Eptr = new workman (string(""),string(""),0,0);
or better yet overload employee() to support this
Code:
workman (char *fname,char *lname,int hours, double salary);
or maybe const char *s.
-
Your constructor takes a string reference that is not to const and a string literal cannot be converted to a plain reference. Make it const string& in your constructors.
-
It's not the same thing. "string" is the name of a C++ class, while "" defines a constant character array.
Code:
int main ()
{ int Choise;
cout <<"Welcome! "<< endl;
employee *Eptr = new workman ("","",0,0);
return 0;
}
is the same as
Code:
int main ()
{ int Choise;
cout <<"Welcome! "<< endl;
const char *loser ="";
employee *Eptr = new workman (loser,loser,0,0);
return 0;
}
Edit: whoah, that was quick.
-
>> char *loser ="";
This should be const char* loser = "".
But simply adding the const to the reference for the constructor parameters is the only change that needs to be made.
-
ah yes, i was relooking in my book and it also shows a const string... ty guys :P that was quite quicky :P