操作符重载成员还是非成员函数选择【c++ primer 】
来源:互联网 发布:mysql删除表数据语句 编辑:程序博客网 时间:2024/04/24 17:13
When designing the overloaded operators for a class, we must choose whether to make each
operator a class member or an ordinary nonmember function. In some cases, the programmerhas no choice; the operator must be a member.
In other cases, there are some rules of thumb that can help guide the decision. The following guidelines can be of help when deciding whether
to make an operator a member or an ordinary nonmember function: he assignment (= ), subscript ([] ), call (() ),
and member access arrow (-> ) operators must be defined as members. Defining any of these operators as a nonmember function is
flagged at compile time as an error.
Like assignment, the compound-assignment operators ordinarily ought to be members of the class. Unlike assignment, they are not required to be so and the compiler will not
complain if a nonmember compound-assignment operator is defined.
Other operators that change the state of their object or that are closely tied to their given
typesuch as increment, decrement, and dereferenceusually should be members of the
class.
Symmetric operators, such as the arithmetic, equality, relational,
and bitwise operators, are best defined as ordinary nonmember functions.
- 操作符重载成员还是非成员函数选择【c++ primer 】
- 重载操作符时选择成员还是非成员实现
- 操作符重载应该设计成类成员函数还是普通非成员函数?
- 重载的操作符成员函数与非成员函数
- 4.操作符重载:成员还是非成员 和 5.重载、缺省值以及省略符
- 操作符重载为成员函数还是友元函数?
- 将重载运算符定义为成员函数还是普通的非成员函数
- C++基础知识复习--运算符重载(非成员函数重载和成员函数重载)
- C#学习之静态成员和非静态成员,构造函数,方法,方法参数,操作符重载,事件
- Day41、静态成员变量、静态成员函数、单例模式、成员/成员函数指针、操作符重载、友元函数
- C++ 友元函数和非成员运算符重载
- 运算符重载 定义为类成员函数or非成员函数
- 操作符重载:类成员函数和全局函数
- 为什么有的操作符重载函数只能是成员函数?
- 运算符重载 成员函数
- 第二遍C++primer->const成员函数
- 如何写二元操作符重载的成员函数版
- 运算符重载(重载为成员函数)
- linux下利用framebuffer画点的程序小例子
- 自编 socket 通信示例
- 代码自动生成-宏带来的奇计淫巧
- C#多线程编程(1):线程的启动
- 寻找合适人才
- 操作符重载成员还是非成员函数选择【c++ primer 】
- 2010公司处级聚会尾牙主持词
- live555的Media.hh学习
- 自己动手做计算机-计算机科学的本质
- JS中报告"return"语句在函数之外
- C++转向C#的疑惑:难道C#中没有拷贝构造函数?
- 心态非常浮躁,不知道该做什么
- LINUX下操作常用命令命令(1)
- [facebook开发系列之四]Graph API原理