无法解决此错误,请帮助我。 我不知道要尝试什么,我之前没有做过运算符>>重载。 我不知道为什么会出现此错误。 如果我解决了这个问题,我想从文件中读取此重载。
代码如下:
input('''Oh, you. You are finally awake. You have been out cold
for the last 10 hours! I am {giant}, and I will be your guide in
defeating the dark lord Thaldmemau. Well, shall we get to it?
A: Where am I?
B: Ok, we will go!
C: Who are you again?)'''.format(giant=giant))
此行中的问题:
#include "Diak.h"
Diak::Diak(string vn, string kn, double a)
{
this->vnev = vn;
this->knev = kn;
this->atlag = a;
}
double Diak::getAtlag() const
{
return this->atlag;
}
string Diak::getVnev() const
{
return this->vnev;
}
string Diak::getKnev() const
{
return this->knev;
}
ostream& operator<<(ostream& os, const Diak& diak)
{
os << diak.vnev << " " << diak.knev << " " << diak.atlag << endl;
return os;
}
istream& operator>>(istream& is, const Diak& diak)
{
is >> diak.vnev >> diak.knev >> diak.atlag;
return is;
}
bool operator<(const Diak& d1, const Diak& d2)
{
if (d1.getVnev() < d2.getVnev())
{
return true;
}
else if(d1.getKnev() == d2.getKnev())
{
if (d1.getKnev() < d2.getKnev())
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
答案 0 :(得分:0)
我只需要从实现和声明(在头文件中)中删除const。