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;
}
输出信息
c++ 逗号操作符重载的更多相关文章
- C++中逗号操作符重载的分析
1,关注逗号操作符重载后带来的变化: 2,逗号操作符: 1,逗号操作符(,)可以构成都好表达式:exp1, exp2, exp3, ..., expN 1,逗号表达式用于将多个表达式连接为一个表达式: ...
- C++语法小记---重载逗号操作符
重载逗号操作符 逗号操作符算法:从左到右依次计算每一个表达式的值,整个逗号表达式的值等于最右边表达式的值,前面n-1个表达式可以没有返回值 重载逗号操作符: 参数必须有一个class成员 重载函数返回 ...
- C++学习笔记15:操作符重载的函数原型列表(推荐)
//普通四则运算 friend A operator +(const A & lhs, const A & rhs); friend A operator -(const A & ...
- __VA_ARGS__与逗号操作符的巧妙结合
class Test { public: template<class T> Test& operator,(T t) { //具体操作 return *this; } } Tes ...
- 15.C++-操作符重载
首先回忆下以前学的函数重载 函数重载 函数重载的本质为相互独立的不同函数 通过函数名和函数参数来确定函数调用 无法直接通过函数名得到重载函数的入口地址 函数重载必然发生在同一个作用域中 类中的函数重载 ...
- 15.C++-操作符重载、并实现复数类
首先回忆下以前学的函数重载 函数重载 函数重载的本质为相互独立的不同函数 通过函数名和函数参数来确定函数调用 无法直接通过函数名得到重载函数的入口地址 函数重载必然发生在同一个作用域中 类中的函数重载 ...
- c++ 操作符重载和友元
操作符重载(operator overloading)是C++中的一种多态,C++允许用户自定义函数名称相同但参数列表不同的函数,这被称为函数重载或函数多态.操作符重载函数的格式一般为: operat ...
- paip.操作符重载的缺失 Java 的一个大缺点
paip.操作符重载的缺失 Java 的一个大缺点 #----操作符重载的作用 1.提升用户体验 操作符重载..可以让代码更加自然.... 2.轻松实现代码代码移植 例如 java代码会直接移植到 ...
- C#中如何利用操作符重载和转换操作符
操作符重载 有的编程语言允许一个类型定义操作符应该如何操作类型的实例,比如string类型和int类型都重载了(==)和(+)等操作符,当编译器发现两个int类型的实例使用+操作符的时候,编译器会生成 ...
随机推荐
- 初识.NET Core
dotnet new console dotnet new web dotnet new webapi dotnet run dotnet build -r win-x64 dotnet publis ...
- 【记忆化搜索】bzoj1055 [HAOI2008]玩具取名
f(l,r,c)表示sl...sr能否被合成字符c. #include<cstdio> #include<cstring> using namespace std; int m ...
- noip2017集训测试赛(三) Problem B: mex [补档]
Description 给你一个无限长的数组,初始的时候都为0,有3种操作: 操作1是把给定区间[l,r][l,r] 设为1, 操作2是把给定区间[l,r][l,r] 设为0, 操作3把给定区间[l, ...
- 13南理工test01:进制转化
#include<iostream> #include<cstdlib> using namespace std; int main() { //cout<<5/2 ...
- Java高级架构师(一)第20节:X-gen生成需要的Action
package cn.javass.themes.smvcsm.actions; import cn.javass.xgen.genconf.vo.ModuleConfModel; import cn ...
- jeeplus中两个项目redis冲突问题
修改端口号[两个项目使用不同的database]
- sql字段字符用做其他类型查询
select * FROM aa where parent = %@ ORDER BY cast(seq as integer) ASC
- centos 7.3systemctl工具
http://www.cnblogs.com/tswcypy/p/4479153.html
- Swift,简单语法
1.创建变量 var a=0 //变量 let b=0 //常量 let b:String="你好" //:后可以定义类型(变量一旦定义,类型不可改变)(类型不填Swift会自动判 ...
- chromatic aberration
https://github.com/keijiro/KinoFringe https://en.wikipedia.org/wiki/Chromatic_aberration 色差偏移 做神经病效果 ...