C++ C++;重载运算符链接排序列表ADT

C++ C++;重载运算符链接排序列表ADT,c++,operator-overloading,adt,C++,Operator Overloading,Adt,我一直在试图使相等(=)和小于( //我不确定 目的地城市是我想要的 应该写 你不应该:-)。如果要在某个类上定义运算符

我一直在试图使相等(=)和小于( //我不确定 目的地城市是我想要的 应该写

你不应该:-)。如果要在某个类上定义
运算符DestinationCity,other.DestinationCity))
...
}

如果您使用的是
std::string
,请不要与
strcmp
进行比较
=
如果要使“struct”不包含成员,可以将二进制运算符定义为非成员:

bool operator <(const flightRec& lhs, const flightRec& rhs) 
{
   if (strcmp(lhs.DestinationCity, rhs.DestinationCity) < 0)
        return true;
    else
        return false;
}

bool操作符flightRec是一个结构,而不是一个类。我试图更改您添加的内容,但它给了我:sortedListClass.cpp:185:50:error:no'bool flightRec::operator@AthetiusC++中的结构和类完全是一样的。唯一的区别是,如果使用
class
,基类和成员默认为
private
,如果使用
struct
,基类和成员默认为
public
。我的代码只是一个示例。您需要移动
operator@Athetius:您的老师可能正在使用(和教授)一种风格,即您对不打算提供任何重要成员函数、任何私有数据成员或任何基类的类使用
struct
关键字,对其他所有类使用
class
。但是风格是你选择如何使用语言,而不是语言的实际内容。。。
bool flightRec::operator< (const flightRec& other) {
   // compare this and other
   if (strcmp(this->DestinationCity, other.DestinationCity))
   ...
}
bool operator <(const flightRec& lhs, const flightRec& rhs) 
{
   if (strcmp(lhs.DestinationCity, rhs.DestinationCity) < 0)
        return true;
    else
        return false;
}