+ 1
use a class methode withouth a instance
is it possibble to use a class methode without making a instance, something like this: https://code.sololearn.com/cbbe6QJSzd6P/?ref=app
8 Respostas
+ 2
Namespaces are there to prevent the collision of names.
For example the standard library has class vector inside the std namespace.
If you use another library like a graphic library, it isn't uncommon that there is another class called vector ( the math version ) in its own namespace.
Without the namespaces your compiler wouldn't be able to tell which one you want to use.
So they prevent ambiguity issues.
So having a class just with static functions probably isn't a better alternative than a namespace.
+ 4
Yes, just use myClass::hi() instead of myClass.hi() if the function is static.
( and move the class above main )
+ 1
Dennis it now works but what does the "::" mean, i know it i used for namesspaces but i dont really know much about those either
0
Dennis aren't namespaces and static classes then basicly the same thing?
0
Pretty much, yea. Except that they can be private in a class.
0
Dennis oh yeah, but then what are namespaces used for?
0
Dennis thabk you, i now understand it