错在哪里,请指点
#include <iostream>
#include "Class.h "
using namespace std;
employee::employee()
{
mName = " ";
mNumber = -1;
mSalary = key;
fHired = false;
}
void employee::promote(int rais)
{
setsalary(getsalary() + rais);
}
void employee::hire()
{
fHired = true;
}
void employee::fire()
{
fHired = false;
}
void employee::display()
{
cout < < "empolyee: " < <getname() < <endl;
cout < < "---------------------------- " < <endl;
cout < <(fHired? "Current Employee ": "Former Employee ") < <endl;
cout < < "Employee Number: " < <getnumber() < <endl;
cout < < "Salary:$ " < <getsalary() < <endl;
cout < <endl;
}
void employee::setname(string name)
{
mName = name;
}
string employee::getname()
{
return mName;
}
void employee::setnumber(int number)
{
mNumber = number;
}
int employee::getnumber()
{
return mNumber;
}
void employee::setsalary(int salary)
{
mSalary = salary;
}
int employee::getsalary()
{
return mSalary;
}
bool employee::getIsHired()
{
return fHired;
}
int main()
{
employee emp;
emp.setname( "camus ");
emp.setnumber(23);
emp.setsalary(50000);
emp.promote();
emp.promote(50);
emp.hire();
emp.display();
return 0;
}
1.(cout < < "empolyee: " < <getname() < <endl; 错误1 error C2679: binary ' < < ' : no operator found which takes a right-hand operand of type 'void ' (or there is no acceptable conversion)c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\shishi\shishi\yuangongguanli.cpp)
2.(string employee::getname()
{
return mName;
}
错误2 error C2556: 'std::string employee::getname(void) ' : overloaded function differs only by return type from 'void employee::getname(void) 'c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\shishi\shishi\yuangongguanli.cpp45)
3.错误3 error LNK2019: 无法解析的外部符号 "public: void __thiscall employee::setname(class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > ) " (?setname@employee@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z),该符号在函数 _main 中被引用yuangongguanli.obj
小弟初学C++,以上是我编写的员工信息管理系统,编译出错,最后一个错误最难以理解,为什么会出现无法解析呢,请各位指点迷津,感激不尽
[解决办法]
1.(cout < < "empolyee: " < <getname() < <endl; 错误1 error C2679: binary ' < < ' : no operator found which takes a right-hand operand of type 'void ' (or there is no acceptable conversion)c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\shishi\shishi\yuangongguanli.cpp)
2.(string employee::getname()
{
return mName;
}
错误2 error C2556: 'std::string employee::getname(void) ' : overloaded function differs only by return type from 'void employee::getname(void) 'c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\shishi\shishi\yuangongguanli.cpp45)
1 和 2 是同一个错误
你应该是在头文件中这么声明的
void getname();
而你在源文件中这么定义
string employee::getname()
{
return mName;
}
getname()应该由一个对象来调用
第三个不太清楚
LZ 把代码贴全了
[解决办法]
1,2错误编译器已经说得相当明白了,你难道看不懂么,第3条因为你的前两条错误,编译器没生成obj文件,主程序main中的函数地址无法链接
[解决办法]
display是成员函数,为什么要用getname()函数?? 函数调用是需要时间和空间的阿。
