Why can const int& bind to an int?

后端 未结 8 553
野性不改
野性不改 2021-02-04 04:39

In the C++ primer, I found that const int & can bind with a int object.I don\'t understand that,because I think const int & should bind with a

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 05:05

    const in this example only guarantee that a can not be changed where r is used. Usually this is used for functions that do not change input parameters like:

    int doNotModifyFoo(const int &foo);
    

提交回复
热议问题