After some find and replace refactoring I ended up with this gem:
const class A { };
What does "const class" mean? It seems to compile ok.
Const member functions in C++ C++ProgrammingServer Side Programming. The const member functions are the functions which are declared as constant in the program. The object called by these functions cannot be modified. It is recommended to use const keyword so that accidental changes to object are avoided.
The const keyword specifies that a variable's value is constant and tells the compiler to prevent the programmer from modifying it.
Const (constant) in programming is a keyword that defines a variable or pointer as unchangeable. A const may be applied in an object declaration to indicate that the object, unlike a standard variable, does not change. Such fixed values for objects are often termed literals.
Like member functions and member function arguments, the objects of a class can also be declared as const. an object declared as const cannot be modified and hence, can invoke only const member functions as these functions ensure not to modify the object.
The const
is meaningless in that example, and your compiler should give you an error, but if you use it to declare variables of that class between the closing }
and the ;
, then that defines those instances as const
, e.g.:
const class A { public: int x, y; } anInstance = {3, 4}; // The above is equivalent to: const A anInstance = {3, 4};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With