Ray's playground

 

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 int and double to be valid anywhere a numerical object is. As a result, any function taking arguments of type string, char*, complex, etc., is a reasonable candidate for overloading to eliminate type conversions.  

posted on 2012-03-09 15:34  Ray Z  阅读(201)  评论(0编辑  收藏  举报

导航