c++ 逗号操作符重载
来源:互联网 发布:ios电话拦截软件 编辑:程序博客网 时间:2024/05/20 04:49
Overload Operator Comma
首先看看think in c++ 给出的一个重载的例子
#include <iostream>using namespace std;class After {public: const After& operator,(const After&) const { cout << "After::operator,()" << endl; return *this; }};class Before {};Before& operator,(int, Before& b) { cout << "Before::operator,()" << endl; return b;}int main() { After a, b; a, b; // Operator comma called Before c; 1, c; // Operator comma called} ///:~
下面是实际使用中用到的例子
#include <iostream>#include <typeinfo>using namespace std;class CClient{public: CClient(){}; ~CClient(){};public: CClient& operator,(string str) { strIpAddr_=str; return *this; } CClient& operator,(int nVal) { nPort_=nVal; return *this; }; bool connect() { //Connect(strIpAddr_,nPort_); cout<<"connect to server "<<endl; return true; }public: string strIpAddr_; int nPort_;};struct OutputDebugInfo{ OutputDebugInfo& operator,(string str) { cout<<str; }};#define outputDebugInfo OutputDebugInfo{},int main() { (CClient {},80,"192.168.1.10").connect(); outputDebugInfo "Log: this is Debug Infomation Test \n"; return 0;}
输出信息
0 0
- c++ 逗号操作符重载
- 关于c 的逗号操作符
- 关于c 的逗号操作符
- C语言中的逗号操作符
- C++【操作符重载】
- c++::操作符重载
- C++:操作符重载
- C++逗号运算符重载
- 操作符重载(C++)
- C++-重载操作符<< >> = + - * /
- c++_操作符重载
- 逗号操作符
- 逗号操作符
- 逗号操作符陷阱
- 逗号操作符
- 逗号操作符
- 逗号操作符
- JavaScript-逗号操作符
- 基于git的源代码管理模型——git flow
- CSS艺术之---负margin之美
- 【学习】http的8种请求方式
- Python/PHP数字螺旋矩阵
- python __init__.py
- c++ 逗号操作符重载
- 告别编译运行 ---- Android Studio 2.0 Preview发布Instant Run功能
- Linux下安装MySQL RPM-Bundle.tar
- PHP 操作redis 详细讲解
- Json.net/Newtonsoft 新特性JObject/Linq to Json
- myeclipse 怎么修改中文字体大小
- 小圆点+无限轮播
- 粒子滤波跟踪方法
- 如何成为包工头