C++构造函数报错error LNK2001:"无法解析的外部符号"
classCEmployee{public:charm_name[30];public:CEmployee();CEmployee(constchar*nm){strcp...
class CEmployee
{
public:
char m_name[30];
public:
CEmployee();
CEmployee(const char* nm)
{
strcpy(m_name,nm);
}
};
class CManeger:public CEmployee
{
public :
float m_salary;
public:
CManager(const char* nm)
{
m_salary=15000.0;
}
void setSalary(float salary)
{
m_salary=salary;
}
}
void main()
{
CManager aManager("小明");
printf("%s\t%f\n",aManager.m_name,aManager.m_salary);
} 展开
{
public:
char m_name[30];
public:
CEmployee();
CEmployee(const char* nm)
{
strcpy(m_name,nm);
}
};
class CManeger:public CEmployee
{
public :
float m_salary;
public:
CManager(const char* nm)
{
m_salary=15000.0;
}
void setSalary(float salary)
{
m_salary=salary;
}
}
void main()
{
CManager aManager("小明");
printf("%s\t%f\n",aManager.m_name,aManager.m_salary);
} 展开
1个回答
展开全部
已改,看注释
class CEmployee
{
public:
char m_name[30];
public:
CEmployee();
CEmployee(const char* nm)
{
strcpy(m_name,nm);
}
};
class CManager:public CEmployee // CManager写错
{
public :
float m_salary;
public:
CManager(const char* nm) : CEmployee(nm) // 需要调用基类构造函数
{
m_salary=15000.0;
}
void setSalary(float salary)
{
m_salary=salary;
}
}; // 漏了分号
void main()
{
CManager aManager("小明");
printf("%s\t%f\n",aManager.m_name,aManager.m_salary);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询