-
global functions and OO
Hello
I never want to have any global functions, instead I always try to put them somewhere..
Im unsure if I should put global functions inside namespace, struct or class (as static functions).
For instance:
Lets say I have int my_random() function, that returns random number.
Should I put it inside a namespace or struct/class?
I noticed most of OO programers would do:
Code:
namespace various {
int my_random() { }
}
So what is the best approach?
-
From a design standpoint, it doesn't make sense to add a method to a class that doesn't have anything to do with that particular class. So yes, I would say the best approach is to add that function to a namespace with other various utilities, if you're really that concerned about it.
-
I would put such free functions inside a suitable namespace, since that is what namespaces are for.