What are the (objective) disadvantages of creating a class where all members (attributes, functions) are static? In particular in comparison with the use of a namespace? Or would you rather create global variables/functions?
I like creating static attributes because I find them "tidier." (I know exactly where they come from, etc.) I'm not very familiar with namespaces. And I'm not comfortable at all with global variables, because I'm not very familiar with C keywords such as extern
and static
.
Further, if we consider the class
class MyStaticClass
{
private:
static int x;
static double y;
public:
static float s;
static double weatherForecast(unsigned int, char);
};
and the namespace
namespace MyNamespace
{
int x;
double y;
float s;
double weatherForecast(unsigned int, char);
}
Are there differences (performance-wise) between calling
MyStaticClass::weatherForecast
and callingMyNamespace::weatherForecast
?Are there differences (performance-wise) between reading/writing
MyStaticClass::s
and reading/writingMyNamespace::s
?Would any of the answers to the above questions change if classes were used instead of primary types?