const参数

    技术2022-05-11  128

    What may be surprising, is that although the parameter is a const inside the function, the compiler otherwise treats the definition of fcn as if we had defined the parameter as a plain int:

    void fcn(const int i) { /* fcn can read but not write to i */ } void fcn(int i) { /* ... */ } // error: redefines fcn(int)

    This usage exists to support compatibility with the C language, which makes no distinction between functions taking const or nonconst parameters.


    最新回复(0)