in C++ by (15.1k points)
0 like 0 dislike

Why is it common declare the function parameters with const modifier, when define function and especially when overloading operators in C++? What it mean?

  • c++ const modifier
  • c++ const function parameter

1 Answer

0 like 0 dislike
by (15.1k points)

The reason to make parameters const is to ensure that they are not changed by the function. This guarantees the caller of the function that the parameters they pass in will not be changed. Modifier const helps you from side effect-related changes of variable mucking up your data in situations where you might not expect it. It is very important in C++ type safety.

Please log in or register to answer this question.