--- id: cpp-inheritance-access title: "C++ Inheritance Access" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["protected access specifier", "C++ ์ƒ์†๊ณผ protected"] 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", "protected"] raw_sources: ["https://www.w3schools.com/cpp/cpp_inheritance_access.asp"] applied_in: [] github_commit: "" --- # [[CPP Inheritance Access]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) This chapter reveals WHY `protected` exists as a third option distinct from `private`: a `private` attribute in the base class would be completely UNREACHABLE by the derived class's own methods, forcing awkward workarounds, while `protected` lets `Programmer`'s `setSalary()`/`getSalary()` methods directly manipulate `Employee`'s `salary` field as if it were their own โ€” meaning `protected` specifically solves the "I need child classes to touch this, but nobody else" access pattern that neither `public` nor `private` alone can express. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`protected`** โ€” similar to `private` (inaccessible from OUTSIDE the class), but UNLIKE `private`, accessible from DERIVED (child) classes. [S1] - **Derived-class methods manipulating a protected base attribute** โ€” `Programmer`'s `setSalary()`/`getSalary()` methods read/write `Employee`'s `protected int salary;` directly, as if it belonged to `Programmer`. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - A protected base attribute manipulated by a derived class's own methods: `class Employee { protected: int salary; }; class Programmer: public Employee { public: int bonus; void setSalary(int s) { salary = s; } int getSalary() { return salary; } }; Programmer myObj; myObj.setSalary(50000); myObj.bonus = 15000;`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **protected๋Š” private๊ณผ public ์‚ฌ์ด์˜ ์ค‘๊ฐ„ ์ง€์ **: ํด๋ž˜์Šค ์™ธ๋ถ€์—์„œ๋Š” ์ ‘๊ทผ ๋ถˆ๊ฐ€ํ•˜๋‹ค๋Š” ์ ์—์„œ private๊ณผ ๊ฐ™์ง€๋งŒ, ํŒŒ์ƒ ํด๋ž˜์Šค์—์„œ๋Š” ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์ ์—์„œ ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒƒ์ด ํ™•์ธ๋จ โ€” ์ด๋Š” private๋งŒ์œผ๋กœ๋Š” ํ•ด๊ฒฐ ๋ชป ํ•˜๋Š” "์ž์‹ ํด๋ž˜์Šค๋งŒ ์ ‘๊ทผ ํ—ˆ์šฉ" ์š”๊ตฌ๋ฅผ ํ•ด๊ฒฐ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) Employee์˜ protected ๊ธ‰์—ฌ(salary)๋ฅผ Programmer ํŒŒ์ƒ ํด๋ž˜์Šค๊ฐ€ ์ž์ฒด getter/setter๋กœ ์ง์ ‘ ๋‹ค๋ฃจ๋Š” ์˜ˆ์ œ๊ฐ€ protected์˜ ๋Œ€ํ‘œ ์‹ค์ „ ํ™œ์šฉ ์‚ฌ๋ก€๋กœ ์›๋ฌธ์— ์ง์ ‘ ์ œ์‹œ๋จ. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) A protected base attribute directly manipulated by a derived class's own methods (C++): ```cpp class Employee { protected: // accessible in derived classes, not outside int salary; }; class Programmer: public Employee { public: int bonus; void setSalary(int s) { salary = s; } int getSalary() { return salary; } }; ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.86 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C++ Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[CPP Inheritance]], [[CPP Access Specifiers]], [[CPP Inheritance Multilevel]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** ์ƒ์†๊ณผ protected โ€” ๋‹ค๋‹จ๊ณ„ ์ƒ์†(Inheritance Multilevel) ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C++ Inheritance Access โ€” https://www.w3schools.com/cpp/cpp_inheritance_access.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Inheritance Access" page (Astra wiki-curation, P-Reinforce v3.1 format).