1
我试图超载运算符为一个作业项目< <。我不断得到一个错误代码4430缺少类型说明符 - 假设为int。注意:C++不支持默认输入。任何帮助将是伟大的!错误4430当超载<<运算符
//EmployeeInfo is designed to hold employee ID information
#ifndef EMPLOYEEINFO_H
#define EMPLOYEEINFO_H
#include <iostream>
#include <ostream>
using namespace std;
std::ostream &operator << (std::ostream &, const EmployeeInfo &);
class EmployeeInfo
{
private:
int empID;
string empName;
public:
//Constructor
EmployeeInfo();
//Member Functions
void setName(string);
void setID(int);
void setEmp(int, string);
int getId();
string getName();
string getEmp(int &);
//operator overloading
bool operator < (const EmployeeInfo &);
bool operator > (const EmployeeInfo &);
bool operator == (const EmployeeInfo &);
friend std::ostream &operator << (std::ostream &, const EmployeeInfo &);
};
friend std::ostream operator<<(std::ostream &strm, const EmployeeInfo &right)
{
strm << right.empID << "\t" << right.empName;
return strm;
}
#endif
请问你的编译器显示哪一行的错误对应?如果是这样,哪一行? – 2013-03-04 02:04:32
首先,检查朋友'std :: ostream运算符<<(std :: ostream&strm,const EmployeeInfo&right)' 定义。在课堂之外不允许“朋友”。 – 2013-03-06 20:13:14
'operator <<'的声明和定义是不同的。将定义更改为:'std :: ostream&operator <<(std :: ostream&,const EmployeeInfo&){...}' – 2013-03-06 20:14:12