concept of overloading in C++

前端 未结 3 1827
情话喂你
情话喂你 2021-01-28 03:48

case 1: you can overload two functions namely:

void foo(int *);
void foo(const int *);

while in , case 2: you can not overload two functions:

3条回答
  •  清酒与你
    2021-01-28 04:09

    Top level CV qualifications for formal arguments are ignored wrt. determining the function's type.

    (CV: const or volatile)

    One way to understand it is, there is no way a top level CV qualification of a formal argument can affect a caller of the function, and it can't affect the machine code. It's only about restrictions on the implementation. So given a declaration void foo( int ) you can use void foo( const int ) for the implementation, or vice versa, if you want.

提交回复
热议问题