//salary.h头文件
using namespace std;
class Emplyee
{
public:
Emplyee(string strName, int nYears)
:m_strName(strName), m_nYears(nYears)
{}
virtual int GetSalary(void);
string Getname()
{
return m_strName;
}
protected:
string m_strName;
int m_nYears;
};
class Manager :public Emplyee
{
public:
Manager(string strName, int nYears)
:Emplyee(strName, nYears)
{}
virtual int GetSalary(void)
{
return 5000 * m_nYears + 10000;
}
};
class Woker : public Emplyee
{
public:
Woker(string strName, int nYears)
:Emplyee(strName, nYears)
{}
virtual int GetSalary(void)
{
return 10 * m_nYears;
}
};
const int max_const = 1000;
class salarysystem
{
public:
salarysystem();
~salarysystem();
void InputEmplyee();
void Displaysalary();
private:
int m_ncount;
Emplyee *m_arrEmplyee[max_const];
};
// salarysystem.cpp : 定义控制台应用程序的入口点。
//
using namespace std;
salarysystem::salarysystem()
{
m_ncount = 0;
}
salarysystem::~salarysystem()
{
for (int i=0; i <= m_ncount; i++)
{
Emplyee* n;
n = m_arrEmplyee[i];
delete n;
}
}
void salarysystem::InputEmplyee()
{
string name;
int year;
bool a;
int member=0;
while (member<max_const)
{
cout << "姓名:";
cin >> name;
if (name == "end")
{
break;
}
cout << "年:";
cin >> year;
cout << "是否为经历(0为不是)";
cin >> a;
member = member + 1;
if (a)
{
m_arrEmplyee[member] = new Manager(name, year);
}
else
{
m_arrEmplyee[member] = new Woker(name, year);
}
}
}
void salarysystem::Displaysalary()
{
string n;
int m;
for (int i = 0; i < max_const; i++)
{
m=m_arrEmplyee[i]->GetSalary();
n = m_arrEmplyee[i]->Getname();
cout << m << endl << n << endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
salarysystem a;
a.InputEmplyee();
a.Displaysalary();
}
错误 1 error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall Emplyee::GetSalary(void)" (?GetSalary@Emplyee@@UAEHXZ) C:\Users\Ghast\Documents\Visual Studio 2013\Projects\工资系统\salarysystem\salarysystem\salarysystem.obj salarysystem
错误 2 error LNK1120: 1 个无法解析的外部命令 C:\Users\Ghast\Documents\Visual Studio 2013\Projects\工资系统\salarysystem\Debug\salarysystem.exe 1 1 salarysystem
不知道错在哪
1
choury 2015-06-01 23:49:58 +08:00
你应该吧GetSalary定义成Emplyee的一个虚函数,纯的也行
|
3
choury 2015-06-02 00:03:43 +08:00 1
|
4
sketch33 2015-06-02 00:09:46 +08:00 1
无责任瞎答
virtual int GetSalary(void); 改为 virtual int GetSalary(void) = 0; 以及 member = member + 1; 这一行要移到他下面那个if语句之后 |
5
cmheia 2015-06-02 11:14:39 +08:00
只有我觉得 pragma once 前面没有 # 很奇怪吗?
|
6
matthewgao 2015-06-02 13:11:24 +08:00
定义是一方面,另外强烈不建议用数组存储的指针用来进行多态操作,有潜在的问题会导致错误。可以用考虑用vector
|