C++ Chapter 01. C언어 기반의 C++ 1. 


01-2 함수 오버로딩(Function Overloading)


* 함수 오버로딩의 이해

// C++은 호출할 함수를 찾을 때, 다음 두 가지 정보를 동시에 활용한다.

1. 함수의 이름

2. 매개변수의 선언



* 함수 오버로딩의 예

// 매개변수의 자료형 또는 개수가 다르다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
 
void MyFunc(void) // ()
{
    std::cout<<"MyFunc(void) called"<<std::endl;
}
 
void MyFunc(char c) // ('A')
{
    std::cout<<"MyFunc(char c) called"<<std::endl;
}
 
void MyFunc(int a, int b) // (12,13)
{
    std::cout<<"MyFunc(int a, int b) called"<<std::endl;
}
 
int main(void)
{
    MyFunc();
    MyFunc('A'); // 그냥 A하면 되지가 않음
    MyFunc(1213);
    return 0;
}
cs








Posted by 너래쟁이
: