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