0
why we need a const class ?
why we need a const class or const struct ?(in cpp)
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.
+ 1
Oh, that's not valid c++. http://stackoverflow.com/questions/206998/what-does-const-class-mean
+ 1
I meant something like this
const class something{
};
+ 1
thank ya ;)