Skip to content

Latest commit

 

History

History

ch14

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14.1 不同:直接调用重载运算符;重载运算符要么是类成员要么有一个参数为类类型;运算符原有表达意义改变,例如逻辑与或
逗号运算符。
相同:运算符优先级相同。
14.3 (a)二者都不是 (b) string (c) vector (d) string
14.4 (a) 因为一般返回值,友元 (b)成员  (c) 成员  (d) 成员 (e) 友元  (f)友元 (g)友元 (h)成员
14.5 (a)(b) (c) (f)需要定义
14.14 operator+= 减少临时对象生成
14.21 不必要的临时对象构造;
14.29 递增递减均会改变对象状态;
14.31 因为没有动态内存需要管理,合成拷贝构造和合成拷贝赋值可以处理。
14.33 与普通函数操作数相同,可以有256个。
14.34 class temp{
    int operator()(bool a,int b, int c)
    {
        return a?b:c;
    }
};
14.41当函数对象没有频繁使用或是复杂时,使用lambda;
14.45 定义转换运算符,容易误解。explicit阻止隐式转换。
14.47 operator const int() 无意义,被编译器忽略
operator int() const 常量表达式
14.50 ex1初始化产生二义性,ex2合法
14.51 cal(int)匹配
匹配原则:1 完全匹配 2.const转换 3.提升类型 4.算数或指针转换 5.类类型转换
14.52  ld = si + ld 二义性
ld = ld + si 均可