问题描述
- 类构造函数的参数转换错误
-
:Employee(const int,const std::string &,const std::string &,int,int,int)' : cannot convert parameter 1 from 'const std::string' to 'const int'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
解决方案
需要int,你传了string,你的构造函数调用不正确。
解决方案二:
错误很明显啊。你第一个参数是int。你却传了string类型。
解决方案三:
CommissionEmployee::CommissionEmployee(const string &first,const string &last,
const string &ssn,int month,int day,int year,double sales,double rate)
:Employee(first,last,ssn,month,day,year)在这报错
解决方案四:
Employee::Employee( const string &first, const string &last,
const string &ssn, int month, int day, int year )
: firstName( first ), lastName( last ), socialSecurityNumber( ssn ),
birthDate( month, day, year )
{
}
void Employee::setFirstName( const string &first )
{
firstName = first;
}
string Employee::getFirstName() const
{
return firstName;
}
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include
#include "Date.h"
using namespace std;
class Employee
{
public:
Employee(const string&,const string &,const string &,
int, int, int);
void setFirstName(const string &);
string getFristName() const;
void setLastName(const string &);
string getLastName() const;
void setSocialSecurityNumber(const string &);
string getSocialSecurityNumber() const;
void setBirthDate(int,int,int);
Date getBirthDate() const;
virtual double earnings () const=0;
virtual void print () const;
private:
string firstName;
string lastName;
string socialSecurityNumber;
Date birthDate;
};
#endif
麻烦看一下