8.10 Function overload differentiation

주홍영·2022년 3월 13일
0

Learncpp.com

목록 보기
86/199

https://www.learncpp.com/cpp-tutorial/function-overload-differentiation/

How overloaded functions are differentiated

함수를 같은 이름에 overload하기 위해서는 이름을 공유하는 각 함수가
서로 differentiated 되어야 한다
이러한 differentiated의 가장 쉬운 방법은
Number of parameters, Type of parameters 를 이용해 차별화 하는 것이다
단, return type으로 differentiated 되니 않는다
참고로 type alias도 근원적으로 다른 type이 아니지 않는한 differentiate X

The return type of a function is not considered for differentiation

int getRandomValue();
double getRandomValue();

두 함수를 위와 같이 정의했을 때 컴파일 에러가 발생한다

생각해보면 우리가 사용할 때 다음과 같이 사용할 것이다

getRandomValue();

만약 컴파일러 입장에서 봤을 때, 두 함수 중 어떤 함수를 call 해야 할까?

profile
청룡동거주민

0개의 댓글