#include <iostream>

// overloading "operator >> " outside class
// >> 应该定义在类之外。 ////////////////////////////////////////////////////////// class Rectangle
{
public:
Rectangle(int w, int h)
: width(w), height(h)
{}; ~Rectangle() {}; public:
int width;
int height;
}; ////////////////////////////////////////////////////////// std::istream&
operator>> (std::istream& is, Rectangle& rec)
{
is >> rec.width >> rec.height;
return is; } std::ostream&
operator<< (std::ostream& os, const Rectangle& rec) // 这里的 const 是必要的,rec应该是一个常量,请注意
{
os << rec.width << ", " << rec.height;
return os; } ////////////////////////////////////////////////////////// int main()
{
Rectangle a(40, 10);
std::cin >> a; std::cout
<< "a = " << a << std::endl; return 0;
}

  

最新文章

  1. Some About Spring
  2. java-内省与javabean
  3. Ubuntu Gnome 14.04.2 lts 折腾笔记
  4. Nikola的5项依赖注入法则
  5. [kipmi0]进程导致系统负载高
  6. postgresql downgrade issue
  7. scala实现Netty通信
  8. sed用法小结
  9. UML学习笔记之类之间的关系
  10. ImageMagick图片服务器
  11. C# 多线程学习笔记 - 1
  12. Windchill基本业务对象-文档
  13. python的内置函数time
  14. LeetCode 1:1. 两数之和
  15. nodejs的__dirname,__filename,process.cwd()区别
  16. Windows 10无法使用debug的解决方案
  17. 【ocp-12c】最新Oracle OCP-071考试题库(43题)
  18. 虚拟机下的zookeeper集群安装
  19. Android中自定义弹出PopupWindow后返回按键失效的问题解决
  20. Android 查看和管理sqlite数据库

热门文章

  1. C#使用Linq to csv读取.csv文件数据2_处理含有非列名数据的方法(说明信息等)
  2. Java生鲜电商平台-系统异常状态的设计与架构(APP应用或者生鲜小程序)
  3. linux下的服务器上传与下载
  4. TimeSpan的用法
  5. PHP $_SERVER超全局变量详解
  6. redis5.0.0功能介绍以及主从集群、哨兵搭建
  7. web项目的初始搭建和intellij的tomcat的配置
  8. C++ 进阶笔记之一
  9. Shell脚本监控CPU、内存和硬盘利用率
  10. 通过BGP实现流量劫持