Ray's playground

 

2012年3月9日

Item 21: Overload to avoid implicit type conversions.(More Effective C++)

摘要: Overloading to avoid temporaries isn't limited to operator functions. For example, in most programs, you'll want to allow a string object everywhere a char* is acceptable, and vice versa. Similarly, if you're using a numerical class like complex (see Item 35), you'll want types like 阅读全文

posted @ 2012-03-09 15:34 Ray Z 阅读(205) 评论(0) 推荐(0)

Item 20: Facilitate the return value optimization.(More Effective C++)

摘要: The rules for C++ allow compilers to optimize temporary objects out of existence. As a result, if you call operator* in a context like this,Rational a = 10;Rational b(1, 2);Rational c = a * b; // operator* is called here your compilers are allowed to eliminate both the ... 阅读全文

posted @ 2012-03-09 14:08 Ray Z 阅读(195) 评论(0) 推荐(0)

导航