--- id: cpp-polymorphism title: "C++ Polymorphism" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["method overriding", "many forms", "C++ λ‹€ν˜•μ„±"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.86 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "oop", "polymorphism"] raw_sources: ["https://www.w3schools.com/cpp/cpp_polymorphism.asp"] applied_in: [] github_commit: "" --- # [[CPP Polymorphism]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Polymorphism is explicitly framed as Inheritance's NATURAL EXTENSION, not a separate feature β€” the source states "Inheritance lets us inherit... Polymorphism uses those methods to perform different tasks," meaning a `Pig` and `Dog` REDEFINING the SAME method name (`animalSound()`) inherited from `Animal` isn't a new syntax to learn, it's simply what happens when a derived class writes its own version of a method it already inherited by name. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Polymorphism** β€” "many forms"; occurs when related classes (via inheritance) implement the SAME method name differently, so ONE action behaves differently per class. [S1] - **Method overriding** β€” a derived class REDEFINES a method it inherited from the base class, with the SAME name and signature. [S1] - **Direct extension of inheritance** β€” polymorphism doesn't add new syntax; it's just what happens when derived classes redefine an inherited method name. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Three classes with the SAME method name, each behaving differently: `class Animal { public: void animalSound() { cout << "The animal makes a sound \n"; } }; class Pig : public Animal { public: void animalSound() { cout << "The pig says: wee wee \n"; } }; class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow \n"; } };` β€” calling `.animalSound()` on each object type produces its own class's version. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - ν˜„μž¬κΉŒμ§€ 발견된 λͺ¨μˆœ 사항 μ—†μŒ (No contradictions found in available sources). ## πŸ› οΈ 적용 사둀 (Applied in summary) Animal 기반 클래슀의 animalSound()λ₯Ό Pig와 Dogκ°€ 각각 λ‹€λ₯΄κ²Œ μž¬μ •μ˜ν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨(λ™μΌν•œ 행동, ν΄λž˜μŠ€λ§ˆλ‹€ λ‹€λ₯Έ κ΅¬ν˜„). [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) The same method name behaving differently across sibling derived classes (C++): ```cpp class Animal { public: void animalSound() { cout << "The animal makes a sound \n"; } }; class Pig : public Animal { public: void animalSound() { cout << "The pig says: wee wee \n"; } }; class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow \n"; } }; ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Inheritance Multiple]], [[CPP Virtual Functions]] - **μ°Έμ‘° λ§₯락:** λ‹€ν˜•μ„± β€” 가상 ν•¨μˆ˜(Virtual Functions) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Polymorphism β€” https://www.w3schools.com/cpp/cpp_polymorphism.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Polymorphism" page (Astra wiki-curation, P-Reinforce v3.1 format).