+ 1

How do you use a class without a object

how do i use a class withouth making it a object for example like the math class. i can just do math.sqrt() and i dont have to make a object like Math mymath;

31st May 2019, 12:34 PM
Cat Sauce
Cat Sauce - avatar
7 Answers
+ 2
Firstly.. Js Math is an object, as everything in js is, there are no classes in js. Just for clarification. About your question there are different solutions in c++ The first is namespaces.. std::sqrt(arg) defined in header <cmath> Second.. as ⚒️Raj Chhatrala🛡️ said you can have static methods. Although in this case is preferable use namespaces ( in js you have to use workarounds to do it ). You also have Template Meta Programming in c++, but it's complicated. I think the real problem is that they are two really different languages, and compare them is not really helpful, Just keep in mind they have different paradigms at a base level, so I suggest to make some researches about paradigm and then start to think and use the language in a proper way. With that in mind everything becomes natural. It's not easy at first stage, especially if you compare c++ and js
31st May 2019, 9:14 PM
AZTECCO
AZTECCO - avatar
+ 3
Absolutely wrong !
31st May 2019, 2:12 PM
AZTECCO
AZTECCO - avatar
+ 2
I think it is not possible in C++. You can access like this in JavaScript. In C++ you have to create a object. Although you can call/invoke a static method without creating instance of class.
31st May 2019, 12:42 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
AZTECCO but i dont compare c++ to js, math is a library in c++
1st Jun 2019, 6:35 AM
Cat Sauce
Cat Sauce - avatar
31st May 2019, 12:45 PM
Cat Sauce
Cat Sauce - avatar
0
AZTECCO please say what is right then
31st May 2019, 5:06 PM
Cat Sauce
Cat Sauce - avatar
0
Good thing you don't, oh.. it is not so bad to compare them, just keep in mind what I said before. Exactly, in js you don't have libraries, you have only objects, when you use the math object in js .. is the js way to use libraries.
1st Jun 2019, 6:43 AM
AZTECCO
AZTECCO - avatar