#include <iostream>

// overloading "operator () " outside class

//////////////////////////////////////////////////////////

class Rectangle
{
public:
Rectangle(const int w, const int h)
: width(w), height(h)
{}; ~Rectangle() {};
int& operator() (const size_t i); public:
int width;
int height;
}; ////////////////////////////////////////////////////////// int &
Rectangle::operator()(const size_t i)
{
if (i == 0)
return width;
else
return height;
} ////////////////////////////////////////////////////////// std::ostream&
operator<< (std::ostream& os, const Rectangle& rec)
{
os << rec.width << ", " << rec.height;
return os; } ////////////////////////////////////////////////////////// int main()
{
Rectangle a(40, 10); std::cout
<< "w = " << a(0) << std::endl // 输出 40
<< "h = " << a(1) << std::endl // 输出 10
; return 0;
}

  

最新文章

  1. 轻量级“集合”迭代器-Generator
  2. Ubuntu安装SSH服务器故障分析及解决办法(错误1:E:软件包 openssh-server 还没有可供安装的候选者,错误2:E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系)
  3. JavaScript(四) Window窗体操作
  4. AccessHelper 需修改
  5. ext grid 子表格
  6. 关于ORACLE隐式转换后性能问题
  7. lodash接触:string-capitalize
  8. iOS代码实践总结
  9. gitlab 安装报错:Could not find modernizr-2.6.2 in any of the sources
  10. lua 函数回调技巧
  11. Javaweb 第15天 web练习和分页技术
  12. tp5上传图片添加永久素材到微信公众号
  13. cocos2d-x工作小记
  14. jquery库的cookie用法
  15. CentOS7用yum快速搭建LAMP平台
  16. XSS理解与防御
  17. Sublime Keymap 设置
  18. jenkins安装及配置-centos6.9
  19. Sequel Pro for Mac(MySQL 数据库管理工具)破解版安装
  20. Python进阶【第三篇】Python中的基本数据类型

热门文章

  1. 在iframe 中视频可以正常播放,但是就是不能全屏。解决方法
  2. C# FlagAttriute 的 小妙招
  3. jQuery总结01_jq的基本概念+选择器
  4. iOS中UICollectionView添加头视图
  5. 使用docker部署filebeat和logstash
  6. 苹果 macOS 安装 Source Code Pro
  7. 反转字符串中的单词 III
  8. HTML连载53-网易注册界面实战之content的头部、content注册信息
  9. C语言程序设计100例之(19):欢乐的跳
  10. Spring Cloud Alibaba 实战(十三) - Sleuth调用链监控