So I just went over cascading member functions calls by returning the *this pointer. I get how it works mechanically but it looks like a large time investment in implementing the functions for gaining the minor ability to one line chain function calls using the dot operator. I’m sure there must be some other benefit beyond simply shortening member function calls but there really isn’t much information about this subject. The first couple pages of google only came up with instructions on how to implement cascaded function calls and nothing about why, how, or where this technique might be useful. Anyone have some useful links that might cover the subject more indepth? Thanks.
So I just went over cascading member functions calls by returning the *this pointer.
Share
The benefit is better-looking code for users of the class when chaining of the operations makes sense. For example:
That may be better to read than either:
Or: