Is the const value parameter in definition but not declaration really C++?

前端 未结 7 1256
时光说笑
时光说笑 2021-01-06 13:31

This is similar to (but different from) this question.

Here is some simple test code to illustrate some weirdness I have discovered with Sun CC:

//--         


        
7条回答
  •  -上瘾入骨i
    2021-01-06 14:03

    This looks like a compiler problem in CC. The C++ standard says (in 13.1 Overloadable declarations):

    Parameter declarations that differ only in the presence or absence of const and/or volatile are equivalent. That is, the const and volatile type-specifiers for each parameter type are ignored when determining which function is being declared, defined, or called.

    But there are const/volatile modifiers that can participate in overloading, as the standard mentions shortly afterwards:

    Only the const and volatile type-specifiers at the outermost level of the parameter type specification are ignored in this fashion; const and volatile type-specifiers buried within a parameter type specification are significant and can be used to distinguish overloaded function declarations.

提交回复
热议问题