--- id: cpp-function-overloading title: "C++ Function Overloading" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["same name different signature", "overload resolution", "C++ 함수 오버로딩"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.87 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "functions", "overloading"] raw_sources: ["https://www.w3schools.com/cpp/cpp_function_overloading.asp"] applied_in: [] github_commit: "" --- # [[CPP Function Overloading]] ## 🎯 한 줄 통찰 (One-line insight) Function overloading is entirely absent from C — C requires a UNIQUE name per function (hence `plusFuncInt`/`plusFuncDouble` as the "without overloading" workaround), while C++ lets MULTIPLE functions share one name (`plusFunc`) as long as their parameter TYPE or COUNT differs, meaning the compiler determines which version to call based on the ARGUMENTS at each call site, not the function name alone — a genuinely new resolution mechanism C never had. [S1] ## 🧠 핵심 개념 (Core concepts) - **Function overloading** — multiple functions sharing ONE NAME, differentiated by parameter type and/or count. [S1] - **Without overloading (the C-style workaround)** — separate function names (`plusFuncInt`, `plusFuncDouble`) needed for logically identical operations on different types. [S1] - **Overloading by type** — `int plusFunc(int x, int y)` and `double plusFunc(double x, double y)` coexist under one name. [S1] - **Overloading by parameter count** — `int plusFunc(int x, int y)` and `int plusFunc(int x, int y, int z)` coexist, differentiated purely by how many arguments are passed. [S1] ## 📖 세부 내용 (Details) - The C-style workaround requiring separate names: `int plusFuncInt(int x, int y) { return x + y; } double plusFuncDouble(double x, double y) { return x + y; }`. [S1] - The same logic unified via overloading: `int plusFunc(int x, int y) { return x + y; } double plusFunc(double x, double y) { return x + y; }` — the compiler picks the right one based on argument types. [S1] - Overloading by parameter count: `int plusFunc(int x, int y) { return x + y; } int plusFunc(int x, int y, int z) { return x + y + z; }` — `plusFunc(3, 7)` calls the 2-parameter version, `plusFunc(1, 2, 3)` calls the 3-parameter version. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **C에는 전혀 없던 오버로딩 개념**: C는 함수마다 고유한 이름이 필요하지만(plusFuncInt/plusFuncDouble처럼), C++는 매개변수의 타입이나 개수만 다르면 같은 이름을 여러 함수에 재사용할 수 있다는 점이 근본적으로 새로운 개념으로 확인됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) int과 double 두 타입에 대해 같은 덧셈 로직을 하나의 plusFunc 이름으로 통합하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1] ## 💻 코드 패턴 (Code patterns) One function name overloaded for two different parameter types (C++): ```cpp int plusFunc(int x, int y) { return x + y; } double plusFunc(double x, double y) { return x + y; } int main() { int myNum1 = plusFunc(8, 5); // calls the int version double myNum2 = plusFunc(4.3, 6.26); // calls the double version return 0; } ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.87 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C++ Tutorial]] - **관련 개념:** [[CPP Function Default]], [[CPP Function Multiple]], [[CPP Constructors Overloading]] - **참조 맥락:** 함수 오버로딩 — 다중 매개변수(Function Multiple) 챕터로 이어짐, 생성자 오버로딩(Constructors Overloading) 챕터와 직접 연결. ## 📚 출처 (Sources) - [S1] W3Schools — C++ Function Overloading — https://www.w3schools.com/cpp/cpp_function_overloading.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Function Overloading" page (Astra wiki-curation, P-Reinforce v3.1 format).