--- id: cpp-inheritance title: "C++ Inheritance" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["base class", "derived class", "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", "inheritance"] raw_sources: ["https://www.w3schools.com/cpp/cpp_inheritance.asp"] applied_in: [] github_commit: "" --- # [[CPP Inheritance]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) The `Car` class never declares a `brand` attribute or a `honk()` method of its own β€” it inherits BOTH directly from `Vehicle` via the single `: public Vehicle` syntax, and `myCar.honk()` works exactly as if `honk()` had been written inside `Car` itself, meaning inheritance in C++ isn't a reference or delegation mechanism but a literal MERGING of the parent's members into the child, accessible with zero extra syntax at the call site. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Inheritance** β€” one class (derived/child) reuses attributes and methods from another (base/parent), avoiding duplication. [S1] - **`: public BaseClass`** β€” the syntax for inheriting; placed after the derived class's name. [S1] - **Zero-syntax access to inherited members** β€” a child object calls inherited methods and reads inherited attributes exactly like its own, with no special prefix. [S1] - **Why inherit** β€” code reusability β€” reuse an existing class's attributes/methods when creating a new one. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - A child class inheriting an attribute and method from its parent: `class Vehicle { public: string brand = "Ford"; void honk() { cout << "Tuut, tuut! \n"; } }; class Car: public Vehicle { public: string model = "Mustang"; }; Car myCar; myCar.honk(); // inherited from Vehicle cout << myCar.brand + " " + myCar.model; // brand inherited, model is Car's own`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - ν˜„μž¬κΉŒμ§€ 발견된 λͺ¨μˆœ 사항 μ—†μŒ (No contradictions found in available sources). ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” Vehicle의 brand와 honk()λ₯Ό Carκ°€ κ·ΈλŒ€λ‘œ λ¬Όλ €λ°›λŠ” μ˜ˆμ œκ°€ 상속을 ν†΅ν•œ μ½”λ“œ μž¬μ‚¬μš©μ˜ λŒ€ν‘œ μ‹€μ „ ν™œμš©μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) A child class inheriting an attribute and method from its parent with zero extra syntax (C++): ```cpp class Vehicle { // Base class public: string brand = "Ford"; void honk() { cout << "Tuut, tuut! \n"; } }; class Car: public Vehicle { // Derived class public: string model = "Mustang"; }; int main() { Car myCar; myCar.honk(); // inherited method, works directly cout << myCar.brand + " " + myCar.model; return 0; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Encapsulation]], [[CPP Inheritance Access]] - **μ°Έμ‘° λ§₯락:** 상속 μ„Ήμ…˜ 첫 챕터 β€” 상속 μ ‘κ·Ό μ§€μ •μž(Inheritance Access) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Inheritance β€” https://www.w3schools.com/cpp/cpp_inheritance.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Inheritance" page (Astra wiki-curation, P-Reinforce v3.1 format).