小编B.J*_*B.J的帖子

头文件和cpp文件中的运算符重载

尝试重载运算符时出现错误。

我的头文件:

#include<iostream>
#include<string>
using namespace std;

#ifndef HALLGATO_H
#define HALLGATO_H

class Hallgato {
    private:
        char* nev;
        char* EHA;
        int h_azon;
        unsigned int kepesseg;
    public:
        friend ostream& operator<<(ostream& output, const Hallgato& H);
};
#endif
Run Code Online (Sandbox Code Playgroud)

我的cpp文件:

#include<iostream>
#include "Hallgato.h"
using namespace std;

    ostream& Hallgato::operator<<(ostream& output, const Hallgato& H) {
        output << "Nev: " << H.nev << " EHA: " << H.EHA << " Azonosito: " << H.h_azon << " Kepesseg: " << H.kepesseg << endl;
        return output;
    }
};
Run Code Online (Sandbox Code Playgroud)

在我的.cpp文件中,当我想定义重载的运算符时<< …

c++ overloading operator-overloading

3
推荐指数
1
解决办法
6808
查看次数

标签 统计

c++ ×1

operator-overloading ×1

overloading ×1