C++ const keyword - use liberally?

前端 未结 12 2437
甜味超标
甜味超标 2020-12-04 18:12

In the following C++ functions:

void MyFunction(int age, House &purchased_house)
{
    ...
}


void MyFunction(const int age, House &purchased_house)         


        
12条回答
  •  醉话见心
    2020-12-04 19:12

    You're correct, the only purpose of "const int age" is that age can not be changed. This can be however very confusing for most of programmers. So if these approach is not used widely in your code, I'd advice to omit const.

提交回复
热议问题