1

宿題プロジェクトの << 演算子をオーバーロードしようとしています。エラー コード 4430 型指定子がありません - int が想定されます。注: C++ はデフォルトインをサポートしていません。どんな助けでも素晴らしいでしょう!

//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
4

1 に答える 1

0

あなたの問題はこの行にあると思います:

std::ostream &operator << (std::ostream &, const EmployeeInfo &);

EmployeeInfoこの行は、クラスの宣言の前に表示されます。つまり、コンパイラは an が何であるかをまだ知りませんEmployeeInfo。その宣言をクラス宣言の後のポイントに移動するか、次のようにクラスを「事前宣言」する必要があります。

class EmployeeInfo; // "Pre-declare" this class

std::ostream &operator << (std::ostream &, const EmployeeInfo &);

class EmployeeInfo
{
    // ... as you have now ...
};
于 2013-03-04T02:08:50.453 に答える