Top "Const-correctness" questions

What is the reason behind cbegin/cend?

I wonder why cbegin and cend were introduced in C++11? What are cases when calling these methods makes a difference …

c++ c++11 iterator const-correctness const-iterator
C++ Overloading Conversion Operators

I am trying to have a class that allows implicit casting to certain built in types, like unsigned long int …

c++ operator-overloading const-correctness
How to call a non-const function within a const function (C++)

I have a legacy function that looks like this: int Random() const { return var_ ? 4 : 0; } and I need to call a …

c++ function constants const-correctness const-cast
Is there some ninja trick to make a variable constant after its declaration?

I know the answer is 99.99% no, but I figured it was worth a try, you never know. void SomeFunction(int …

c++ c++11 const-correctness
What is meaning of a pointer to a constant function?

Pointers can be declared as pointing to mutable (non-const) data or pointer to constant data. Pointers can be defined to …

c function-pointers const-correctness
Sell me on const correctness

So why exactly is it that it's always recommended to use const as often as possible? It seems to me …

c++ const-correctness
Can const-correctness improve performance?

I have read numerous times that enforcing const-correctness in your C or C++ code is not only a good practice …

c++ performance const-correctness
How to call a non-const method from a const method?

I've got a const method in my class, which cannot be changed to non-const. In this method, I need to …

c++ methods constants const-correctness
Why can't I convert 'char**' to a 'const char* const*' in C?

The following code snippet (correctly) gives a warning in C and an error in C++ (using gcc & g++ respectively, …

c pointers constants const-correctness
Why no 'const' in Python?

I come from C background and am learning Python. The lack of explicit type-safety is disturbing, but I am getting …

python constants const-correctness