concept of overloading in C++

前端 未结 3 1868
情话喂你
情话喂你 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:02

    In the second case, because integers are primitive type, the int or const int is passed by value, and the function makes a copy of the variable. Therefore, the function definition is the same.

    In the first case, the first function takes in an integer pointer as a parameter, whereas the second function takes in a pointer to a constant integer. These are different data types, as the value of the integer is not copied by the value of the pointer is, and therefore the data is passed by reference.

提交回复
热议问题