Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Article about free static function usage

I am looking for an article or documentation that explains why a free static function is better than a private member function, when the given function does not modify or read the private members of the class. To my point of view the advantages are :

  • Less dependencies

  • Better encapsulation (for "mammoth" classes, it helps to know that at least those function calls do not modify the members)

I am certain someone has already written something better than what I can do.

like image 885
Palmira Avatar asked Feb 22 '26 23:02

Palmira


1 Answers

Free static functions are passe. One would use a function in the anonymous namespace instead.

They are slightly more maintainable -- since they can't access private members, they are robust against changes to implementation details. A static member function could also be independent of implementation details, but you don't have the compiler verifying that.

like image 88
Ben Voigt Avatar answered Feb 25 '26 14:02

Ben Voigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!