Note that there are some explanatory texts on larger screens.

plurals
  1. POEffective C++ Item 23 Prefer non-member non-friend functions to member functions
    primarykey
    data
    text
    <p>While puzzling with some facts on class design, specifically whether the functions should be members or not, I looked into Effective c++ and found Item 23, namely, Prefer non-member non-friend functions to member functions. Reading that at first hand with the web browser example made some sense, however convenience functions( named the nonmember functions like this in the book) in that example change the state of the class, don't they? </p> <ul> <li><p>So, first question, should not they be members than?</p></li> <li><p>Reading a bit further, he considers the STL functions and indeed some functions which are not implemented by some classes are implemented in stl. Following the ideas of the book they evolve into some convenience functions that are packed into some reasonable namespaces such as <code>std::sort</code>, <code>std::copy</code> from <code>algorithm</code>. For instance <code>vector</code> class does not have a <code>sort</code> function and one uses the stl <code>sort</code> function so that is not a member of the vector class. But one could also stretch the same reasoning to some other functions in vector class such as <code>assign</code> so that could also not be implemented as a member but as a convenience function. However that also changes the internal state of the object like sort on which it operated. So what is the rationale behind this subtle but important (I guess) issue. </p></li> </ul> <p>If you have access to the book can you clarify these points a bit more for me?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload