+ 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

3rd Jun 2019, 2:43 PM
Cat Sauce
Cat Sauce - avatar
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.
3rd Jun 2019, 5:08 PM
Dennis
Dennis - avatar
+ 4
Yes, just use myClass::hi() instead of myClass.hi() if the function is static. ( and move the class above main )
3rd Jun 2019, 2:56 PM
Dennis
Dennis - avatar
+ 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
3rd Jun 2019, 3:24 PM
Cat Sauce
Cat Sauce - avatar
0
Dennis aren't namespaces and static classes then basicly the same thing?
3rd Jun 2019, 4:55 PM
Cat Sauce
Cat Sauce - avatar
0
Pretty much, yea. Except that they can be private in a class.
3rd Jun 2019, 4:57 PM
Dennis
Dennis - avatar
0
Dennis oh yeah, but then what are namespaces used for?
3rd Jun 2019, 5:00 PM
Cat Sauce
Cat Sauce - avatar
0
Dennis thabk you, i now understand it
3rd Jun 2019, 5:44 PM
Cat Sauce
Cat Sauce - avatar