C++中括号()操作符的重载举例及解析
来源:互联网 发布:免费实时港股软件 编辑:程序博客网 时间:2024/04/28 03:38
http://blog.csdn.net/yang_lang/article/details/6725041
C++项目中,经常会遇到使用重载()操作符的地方,请看下面一个例子:
- #include <iostream>
- using namespace std;
- class Clastype
- {
- public:
- Clastype(int a)
- {
- cout << "Hello Clastype!" << a << endl;
- }
- bool operator ()(int b)
- {
- cout << "Hello Clastype()!" << b << endl;
- return true;
- }
- };
- int main()
- {
- Clastype a(1);
- Clastype(2);
- Clastype t = Clastype(3);
- t(4);
- Clastype *b = new Clastype(5);
- (*b)(6);
- }
运行结果如下:
- @-desktop:~/test$ g++ -o o 6.cpp
- @-desktop:~/test$ ./o
- Hello Clastype!1
- Hello Clastype!2
- Hello Clastype!3
- Hello Clastype()!4
- Hello Clastype!5
- Hello Clastype()!6
可见,括号操作符的使用为对象加上()操作符。类名直接加()操作符为对象的创建。
- C++中括号()操作符的重载举例及解析
- C++中括号()操作符的重载举例及解析
- C++中括号()操作符的重载举例及解析
- C++中括号()操作符的重载举例及解析
- C++中括号()操作符的重载举例及解析
- C++中括号()操作符的重载举例及解析
- C++中括号()操作符的重载举例及解析
- C++中括号()操作符的重载自我理解
- c++ ()括号操作符的重载
- 重载 方括号 中括号 [][] [C++]
- 括号操作符重载案例
- C++_函数的重载使用举例
- 括号运算符的重载
- 重载操作符解析
- 重载操作符解析
- C语言中static关键字的常见用法及举例
- C#-MessageBox全部函数重载形式及举例---ShinePans
- C++ 重载中括号
- java读取文件方法大全
- 高级Bash脚本编程指南 一个对脚本编程技术的深入探讨
- SSD将迎来TB时代
- 写技术论文时-文章作者栏目方法
- 深入剖析u-boot命令结构
- C++中括号()操作符的重载举例及解析
- NSUserDefaults实现小型数据的配置管理
- 十三个代码注释的小技巧
- RCP中的org.eclipse.swt.SWTException: Invalid thread access 问题
- 什么是数组名?什么是指针----指针与数组的区别!
- 驱动程序里ioctl下switch问题
- IOS 开发codesign错误
- SOA 11G ANT 编译部署项目
- hive创建分区表问题