作者在这一节中花了大幅度的篇幅来介绍为什么最好使用non-member.non-friend函数. 思路如下: 场景:如果有一个class用来表示网页浏览器,那么清楚缓存及历史记录的时候,我们可能定义下面的类: class Web { public: void clearCache(); void clearCookies(); void clearHistory(); } 但是也有可能用户需要一下子全部清除这些信息,于是我们再定义下面这个成员函数: class Web {public: voi…
1.The Different Kinds of Type Members 1.Constants:a symbol that identifies a never-changing data value.Constants are always associated with a type, not an instance of a type. Logically, constants are always static members 2.Fields:represents a read-o…
之前我们讲过编译器会对 nonmember functions 进行怎样的扩充和该写,今天我们来讲一下 member functions 函数调用方式 一.Nonstatic Member Functions(非静态成员函数) C++的设计准则之一就是:nonstatic member function 至少必须和 nonmember function 有相同的效率.也就是说如果们要在以下两个函数之间选择: float member_fun( const classA *_this){...};…
see:http://www.cplusplus.com/forum/general/136410/ & http://stackoverflow.com/questions/8121320/get-memory-address-of-member-function static member function and dynamic member functions are treated differently. we can just use std::function() to real…