#include <iostream>

// overloading "operator = " outside class
// < 和 > 是二元操作符 ////////////////////////////////////////////////////////// class Rectangle
{
public:
Rectangle(int w, int h)
: width(w), height(h)
{}; ~Rectangle() {}; bool operator< (Rectangle& rec);//注意比较的顺序。this是被比的对象。
bool operator> (Rectangle& rec); public:
int width;
int height;
}; bool
Rectangle::operator< (Rectangle & rec)//相同的class对象互为友元,所以可以访问private对象。< 是二元操作符,class内隐藏了this
{
return this->height * this->width < rec.height * rec.width;
} bool
Rectangle::operator> (Rectangle & rec)//二元操作符,class内隐藏了this
{
return !(*this < rec);
} ////////////////////////////////////////////////////////// int main()
{
Rectangle a(40, 10);
Rectangle b(40, 56); std::cout << (a < b) << std::endl;
std::cout << (a > b) << std::endl; return 0;
}

  

最新文章

  1. 用PHP抓取页面并分析
  2. SQLMAP 中$与#的区别
  3. SparkSql 不支持Date Format (支持Timestamp)
  4. LA 3890 (半平面交) Most Distant Point from the Sea
  5. less-2
  6. 同时处理html+js+jquery+css的插件安装(Spket&amp;Aptana插件安装)
  7. (简单) POJ 1961 Period,扩展KMP。
  8. QT的安装及环境配置
  9. An internal error occurred during: &quot;Requesting JavaScript AST from selection&quot;. GC overhead limit exc
  10. ZOJ-1655 Transport Goods---dijkstra变形&amp;&amp;最长路
  11. MongoDB 数据库引用
  12. 两种方法轻松搞定-- Eclipse 安装FindBugs插件
  13. jenkins忘记admin密码解决办法
  14. 在Django中接收文件并存储
  15. 使用ASP.NET Core的User Secrets特性
  16. it做形式主语的句子
  17. PHP-数据库永久连接
  18. UVALive.3708 Graveyard (思维题)
  19. pyCharm上解决安装不上pandas库问题
  20. MFC学习(三)程序入口和执行流程

热门文章

  1. Linux 和 Windows 查看当前运行的 python 进程及 GPU、CPU、磁盘利用率
  2. python爬虫之爬取网站到数据库
  3. CSP2019 S2滚粗记
  4. C语言中,嵌套的if语句的一些经验...
  5. IDEA debug工具使用
  6. pytest框架之rerunfailures失败重运行机制
  7. HTTP常见的几种认证机制
  8. 【Ajax】Ajax入门总结
  9. java基础(30):DBUtils、连接池
  10. Python 内置函数补充匿名函数