0

why we need a const class ?

why we need a const class or const struct ?(in cpp)

6th Mar 2017, 11:21 AM
Navid Tak
Navid Tak - avatar
4 ответов
+ 1
The const keyword is the C++ version of an immutatable object. There are a lot of uses for this, especially in functional programming. Constness is important because it forces the compiler to assure that the variable can't be changed which used to be done with Macros in C. A good example of the use of const would be things like PI or other mathematical constants because they can't and shouldn't be changed. Without const someone could do something like: PI = 10.0f and we know that that's absurd.
6th Mar 2017, 11:47 AM
Alexandre Sabourin
Alexandre Sabourin - avatar
6th Mar 2017, 1:08 PM
Alexandre Sabourin
Alexandre Sabourin - avatar
+ 1
I meant something like this const class something{ };
6th Mar 2017, 2:26 PM
Navid Tak
Navid Tak - avatar
+ 1
thank ya ;)
6th Mar 2017, 2:33 PM
Navid Tak
Navid Tak - avatar