+ 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;
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
+ 3
Absolutely wrong !
+ 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.
+ 1
AZTECCO but i dont compare c++ to js, math is a library in c++
0
âď¸Raj ChhatralađĄď¸ thank you
0
AZTECCO please say what is right then
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.