读书人

有一个BUG异常 求各位帮帮吧

发布时间: 2013-11-12 12:10:37 作者: rapoo

有一个BUG错误 求各位帮帮吧?

/************************/
/* example of 5.7 */
/************************/

#include<iostream>
#include<string>
using namespace std;


/*********************************************************/
/* class of Employee */
/*********************************************************/
class Employee
{
protected:
char *name; //the number of employee
int individualEmpNo;
int grade; //work position
float accumPay;
static int employeeNo; //The max number of compus emploayee number
public:
Employee()
{name=new char[];
individualEmpNo=employeeNo++;
cout<<"职工姓名:";
cin>>name;
accumPay=0.0;
}

~Employee()
{
cout<<"destructe employee class"<<endl;
}
virtual void pay()=0;
//virtual void promote(); //the money of promote
virtual void displayStatus();
};

/*********************************************************/
/* class of Technician */
/*********************************************************/
class Technician:public Employee
{
private:
float hourlyRate; //the salary of a hour
int workHours; //work hour
public:
Technician()
{
hourlyRate=100;
cout<<name<<"本月工作时间:";
cin>>workHours;
}

void pay()
{
accumPay=hourlyRate*workHours;
}
void displayStatus()
{
cout<<"兼职技术人员:"<<name<<",编号:";
cout<<individualEmpNo<<",本月工资:"<<accumPay<<endl;
}
};

/*********************************************************/
/* class of Manager */
/*********************************************************/
class Manager:virtual public Employee
{
protected:
float monthlyPay;

public:

Manager()
{
monthlyPay=8000;
}

void pay()
{
accumPay=monthlyPay;
}
void displayStatus()
{
cout<<"经理:"<<name<<",编号:";
cout<<individualEmpNo<<",本月工资:"<<accumPay<<endl;
}

};

/*********************************************************/
/* class of Salesman */
/*********************************************************/
class Salesman:virtual public Employee
{
protected:
float commRate;
float sales; //salary of monthy
public:
Salesman()
{
commRate=0.04f;
cout<<name<<"本月销售额:";
cin>>sales;
}
void pay()
{
accumPay=sales*commRate;
}
void display()
{
cout<<"销售员:"<<name<<",编号:";
cout<<individualEmpNo<<",本月工资:"<<accumPay<<endl;
}
};


/*********************************************************/
/* class of Salesmanager */
/*********************************************************/
class Salesmanager:public Manager,public Salesman
{
public:
Salesmanager()
{
monthlyPay=5000;
commRate=0.05f;
cout<<name<<"所管部门月销售量:";
cin>>sales;
}
void pay()
{


accumPay=monthlyPay+commRate*sales;
}

void displayStatus()
{
cout<<"销售经理:"<<name<<",编号:"<<individualEmpNo<<":本月工资:"<<accumPay<<endl;
}
};

int Employee::employeeNo=10000;

int main()
{
Manager m1;
Technician t1;
Salesman s1;
Salesmanager sm1;

Employee *em[4]={&m1,&t1,&s1,&sm1};
cout<<"上述人员的基本信息为:"<<endl;

for(int i=0;i<4;i++)
{
em[i]->pay();
em[i]->displayStatus();
}
return 0;
}


--------------------------------------------------------------------------
Linking...
SDFAs.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Employee::displayStatus(void)" (?displayStatus@Employee@@UAEXXZ)
Debug/ddsaaA.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

看着上面的错误提示 也不知道错在哪里?希望各位 能忙里偷闲 过来帮忙看看 小弟不胜感激。 一个BUG?求能人?帮帮忙吧?
[解决办法]
Manager m1;Technician t1;Salesman s1;Salesmanager sm1;
有的类里没有实现基类的虚函数
[解决办法]
基类Employee的displayStatus函数没有实现
这样:
void displayStatus() { }
[解决办法]
virtual void displayStatus();
改为
virtual void displayStatus(){};
试试

读书人网 >C++

热点推荐