error C2660: “Employee::reset”: 函数不接受 3 个参数
#include<iostream>#include<string>usingnamespacestd;classEmployee{public:Employee(str...
#include <iostream>
#include <string>
using namespace std;
class Employee
{
public:
Employee(string n, int i)
{
name = n;
ID = i;
}
~Employee()
{
}
virtual void reset(string n, int i)
{
name = n;
ID = i;
}
virtual void print()
{
cout << "Employee name: " << name << endl;
cout << "Employee ID: " << ID << endl;
}
string name;
int ID;
};
class Manager :public Employee
{
public:
Manager(string n, int i, double s)
:Employee(n, i)
{
salary = s;
}
void reset(string n, int i, double s)
{
name = n;
ID = i;
salary = s;
}
void print()
{
cout << "Manager name: " << name << endl;
cout << "Manager ID: " << ID << endl;
cout << "Manager salary: " << salary << endl;
}
double salary;
};
int main()
{
Employee *e;
Manager M("borban", 1001, 15000.00);
e = &M;
e->reset("borban", 1001, 16000.00); //error C2660: “Employee::reset”: 函数不接受 3 个参数
e->print();
}
把EMPLOYEE类的reset的virtual去掉,一样会有C2660错误
void reset(string n, int i)
{
name = n;
ID = i;
} 展开
#include <string>
using namespace std;
class Employee
{
public:
Employee(string n, int i)
{
name = n;
ID = i;
}
~Employee()
{
}
virtual void reset(string n, int i)
{
name = n;
ID = i;
}
virtual void print()
{
cout << "Employee name: " << name << endl;
cout << "Employee ID: " << ID << endl;
}
string name;
int ID;
};
class Manager :public Employee
{
public:
Manager(string n, int i, double s)
:Employee(n, i)
{
salary = s;
}
void reset(string n, int i, double s)
{
name = n;
ID = i;
salary = s;
}
void print()
{
cout << "Manager name: " << name << endl;
cout << "Manager ID: " << ID << endl;
cout << "Manager salary: " << salary << endl;
}
double salary;
};
int main()
{
Employee *e;
Manager M("borban", 1001, 15000.00);
e = &M;
e->reset("borban", 1001, 16000.00); //error C2660: “Employee::reset”: 函数不接受 3 个参数
e->print();
}
把EMPLOYEE类的reset的virtual去掉,一样会有C2660错误
void reset(string n, int i)
{
name = n;
ID = i;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询