C++ 头文件和cpp文件中的运算符重载
当我试图使操作员过载时,我出错了 我的头文件:C++ 头文件和cpp文件中的运算符重载,c++,operator-overloading,overloading,C++,Operator Overloading,Overloading,当我试图使操作员过载时,我出错了 我的头文件: #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
#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
#包括
#包括
使用名称空间std;
#哈尔加图酒店
#定义HALLGATO_H
哈尔加托班{
私人:
char*nev;
char*EHA;
int h_azon;
无符号整数kepesseg;
公众:
friend ostream&operator该操作符不是该类的成员,因此它是一个朋友
ostream& Hallgato::operator<<(ostream& output, const Hallgato& H) {
ostream&Hallgato::operator在头文件中为类声明了friend方法
friend ostream& operator<<(ostream& output, const Hallgato& H);
因为此方法不是Hallgato类的一部分。您好B.J,您可以添加收到的错误消息吗?您的文件中似乎有额外的}
。。如果您使用的是Dev-C++5.11(Windows x64),请重新生成所有文件。花了我的时间。
ostream& operator<<(ostream& output, const Hallgato& H) {
#ifndef HALLGATO_H
#define HALLGATO_H
#include<iostream>
#include<string>
class Hallgato {
private:
char* nev;
char* EHA;
int h_azon;
unsigned int kepesseg;
public:
friend std::ostream& operator<<(std::ostream& output, const Hallgato& H);
};
std::ostream& operator<<(std::ostream& output, const Hallgato& H);
#endif /* End of HALLGATO_H */
#include "hallgato.h"
std::ostream& operator<<(std::ostream& output, const Hallgato& H)
{
/* Some operator logic here */
}
friend ostream& operator<<(ostream& output, const Hallgato& H);
ostream& operator<<(ostream& output, const Hallgato& H)