当前位置: 技术问答>linux和unix
C++ 一个类的使用问题
来源: 互联网 发布时间:2014-11-04
本文导语: 昨天写了一个使用类的代码如下: #include class Employee { public: int SetAge(int itsAge); int SetYearOfServeice(int itsYear); int SetSalary(int itsSalary); void Show(void) const; private: int Age; int YearOfServeice; int Salary; }; int Employee::S...
昨天写了一个使用类的代码如下:
#include
class Employee
{
public:
int SetAge(int itsAge);
int SetYearOfServeice(int itsYear);
int SetSalary(int itsSalary);
void Show(void) const;
private:
int Age;
int YearOfServeice;
int Salary;
};
int Employee::SetAge (int itsAge)
{
Age = itsAge;
}
int Employee::SetYearOfServeice(int itsYear)
{
YearOfServeice = itsYear;
}
int Employee::SetSalary(int itsSalary)
{
Salary = itsSalary;
}
void main()
{
Employee proc;
proc.SetAge(32);
proc.SetYearOfServeice(12);
proc.SetSalary(1000);
}
编译后提示出错为:
'Employess::SetAge':must return a value
这是为什么呢?
#include
class Employee
{
public:
int SetAge(int itsAge);
int SetYearOfServeice(int itsYear);
int SetSalary(int itsSalary);
void Show(void) const;
private:
int Age;
int YearOfServeice;
int Salary;
};
int Employee::SetAge (int itsAge)
{
Age = itsAge;
}
int Employee::SetYearOfServeice(int itsYear)
{
YearOfServeice = itsYear;
}
int Employee::SetSalary(int itsSalary)
{
Salary = itsSalary;
}
void main()
{
Employee proc;
proc.SetAge(32);
proc.SetYearOfServeice(12);
proc.SetSalary(1000);
}
编译后提示出错为:
'Employess::SetAge':must return a value
这是为什么呢?
|
其他的几个成员函数没有这个问题吗?