C++ Chapter 01. C언어 기반의 C++ 1. 01-2 함수 오버로딩(Function Overloading)
C,C++/CONCEPT 2018. 2. 28. 09:17 |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(12, 13); return 0; } | cs |
'C,C++ > CONCEPT' 카테고리의 다른 글
C++ Chapter 01. C언어 기반의 C++ 1. 01-4 인라인(inline) 함수 (0) | 2018.02.28 |
---|---|
C++ Chapter 01. C언어 기반의 C++ 1. 01-3 매개변수의 디폴트 값(Default Value) (0) | 2018.02.28 |
C++ Chapter 01. C언어 기반의 C++ 1. 01-1 printf와 scanf를 대신하는 입출력 방식 (1) | 2018.02.28 |
C chapter27. 파일의 분할과 헤더파일의 디자인. 27-3 헤더파일의 디자인과 활용 (0) | 2018.02.23 |
C chapter27. 파일의 분할과 헤더파일의 디자인. 27-2 둘 이상의 파일을 컴파일하는 방법과 static에 대한 고찰 (0) | 2018.02.23 |