C++11 什么是;操作员<&引用;语法意义? 我正在学习C++的STL。我遇到了这个语法,不能弄清楚整条线的意思。p> struct student{ int id,pts; bool operator < (student x) const{ return pts>x.pts; } }a[150000]; struct student{ int id,pts; 布尔运算符x.pts; } }a[150000];

C++11 什么是;操作员<&引用;语法意义? 我正在学习C++的STL。我遇到了这个语法,不能弄清楚整条线的意思。p> struct student{ int id,pts; bool operator < (student x) const{ return pts>x.pts; } }a[150000]; struct student{ int id,pts; 布尔运算符x.pts; } }a[150000];,c++11,syntax,stl,C++11,Syntax,Stl,它为structstudent定义了一个“小于”运算符,以便人们可以编写: student one, two; bool b = one < two; 学生一、二; 布尔b=一,!(myStudentyourstuent)不同?@Arun标准库从不查看运算符>,因此定义它不会使您更接近于降序。最好定义一个特定的函数,如更多点。您还可以定义运算符>,并指定std::morer,或指定std::rel\u ops::operator>作为自定义函数unction,它是用操作符定义的啊,我

它为struct
student
定义了一个“小于”运算符,以便人们可以编写:

 student one, two;
 bool b = one < two;
学生一、二;
布尔b=一<二;

operator<允许比较两个学生,在本例中,它仅通过pts进行比较

struct student{ 
   int id,pts;

   bool operator < (student x) const{
    return pts>x.pts; // must be pts<x.pts
  }
}a[150000];
struct student{
int id,pts;
布尔运算符<(学生x)常数{

return pts>x.pts;//必须是pts),实现必须使用运算符“
运算符这是用于导出STL关系的
+1的重载,如果我想要一个自定义运算符>(降序)?如果没有自定义运算符>,!(myStudentyourstuent)不同?@Arun标准库从不查看
运算符>
,因此定义它不会使您更接近于降序。最好定义一个特定的函数,如
更多点
。您还可以定义
运算符>
,并指定
std::morer
,或指定
std::rel\u ops::operator>
作为自定义函数unction,它是用
操作符定义的啊,我明白了,谢谢@Potatoswatter的解释!
struct student{ 
   int id,pts;

   bool operator < (student x) const{
      return pts<x.pts; 
   }   
   bool operator > (student x) const{
      return pts>x.pts; 
   }
   bool operator == (student x) const{
      return pts == x.pts; 
   }