static members vs namespace helper functions
-
Gday All, I have a performance /design question regarding whether it is better to implement helper functions for a class as static members or as global/namespace functions. For example: namespace MyObjCtrl { class MyObject { public: //static member that uses a MyObject ( option 'A' ) static HelperStyleA( MyObject* pObj ); }; //namespace helper function of option 'B' HelperStyleB( MyObject* pObj ); }; //implementation of option 'B' MyObjCtrl::HelperStyleB( MyObject* pObj ) { } If anyone could give me a run down on the pros and cons of these two methods or of any website or tutorial that might help, it would be much appreciated
-
Gday All, I have a performance /design question regarding whether it is better to implement helper functions for a class as static members or as global/namespace functions. For example: namespace MyObjCtrl { class MyObject { public: //static member that uses a MyObject ( option 'A' ) static HelperStyleA( MyObject* pObj ); }; //namespace helper function of option 'B' HelperStyleB( MyObject* pObj ); }; //implementation of option 'B' MyObjCtrl::HelperStyleB( MyObject* pObj ) { } If anyone could give me a run down on the pros and cons of these two methods or of any website or tutorial that might help, it would be much appreciated
This is actually a C++ question, but I'll answer it. There is not performance issue here just a stylistic one. I personally prefer static functions over global functions as they imply a link to a given context. Cheers, Tom Archer Author, Inside C#