I get the following error and I cannot figure out why:
Could not find a match for 'PEmployee::PEmployee(char *, double)' in function main()
Here’s my code:
class PEmployee
{
public:
PEmployee();
PEmployee(string employee_name, double initial_salary);
void set_salary(double new_salary);
double get_salary() const;
string get_name() const;
private:
Person person_data;
double salary;
};
int main()
{
PEmployee f("Patrick", 1000.00);
cout << f.get_name() << " earns a salary of ";
<< f.get_salary() << endl;
return 0;
}
Can somebody tell me why I get this error?
Thanks.
The constructor for
std::stringwith typechar *is not explicit, so I don’t know why you would get that error. The compiler should recognize that it can create astd::stringon the fly for you.From http://en.cppreference.com/w/cpp/string/basic_string/basic_string: