--- id: cpp-structs title: "C++ Structures (struct)" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["named structures", "anonymous struct", "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", "structs"] raw_sources: ["https://www.w3schools.com/cpp/cpp_structs.asp"] applied_in: [] github_commit: "" --- # [[CPP Structures (struct)]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Once a C++ struct is given a NAME (`struct car {...};`), that name alone becomes a usable data type β€” `car myCar1;` needs NO `struct` keyword before it β€” a direct contrast to C, where `struct car myCar1;` always requires the `struct` keyword UNLESS a separate `typedef` is used; meaning C++ eliminated an entire chapter's worth of C's typedef-with-struct workaround by making named structs behave as first-class types automatically. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Structure (`struct`)** β€” groups multiple MIXED-type variables ("members") into one unit; unlike C, members can include `string` directly. [S1] - **Anonymous struct + variable in one declaration** β€” `struct { int myNum; string myString; } myStructure;` declares the type AND the variable together, with no reusable name. [S1] - **Multiple variables of one anonymous struct** β€” `struct {...} myStruct1, myStruct2, myStruct3;` β€” comma-separated. [S1] - **Named structs behave as data types with NO `struct` prefix needed** β€” `struct car {...}; car myCar1;` β€” unlike C, which always requires writing `struct car myCar1;` unless `typedef` is used. [S1] - **Dot syntax (`.`)** β€” accesses/assigns individual members, same as C. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Anonymous struct with a single variable: `struct { int myNum; string myString; } myStructure; myStructure.myNum = 1; myStructure.myString = "Hello World!";`. [S1] - Named struct usable as a type with no `struct` keyword at the use site: `struct car { string brand; string model; int year; }; car myCar1; myCar1.brand = "BMW";`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **이름 뢙은 κ΅¬μ‘°μ²΄λŠ” struct ν‚€μ›Œλ“œ 없이 νƒ€μž…μ²˜λŸΌ μ‚¬μš© κ°€λŠ₯**: Cμ—μ„œλŠ” typedef μ—†μ΄λŠ” 항상 struct car myCar1;처럼 structλ₯Ό λΆ™μ—¬μ•Ό ν–ˆμ§€λ§Œ, C++μ—μ„œλŠ” struct car {...}; μ„ μ–Έ ν›„ car myCar1;만으둜 μΆ©λΆ„ν•˜λ‹€λŠ” 점이 λͺ…μ‹œμ μœΌλ‘œ 확인됨 β€” C의 typedef-with-struct 챕터가 ν•΄κ²°ν•˜λ˜ 문제λ₯Ό C++λŠ” μ–Έμ–΄ μ°¨μ›μ—μ„œ 이미 ν•΄κ²°ν•œ μ…ˆ. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) Car ꡬ쑰체 ν•˜λ‚˜λ‘œ BMW와 Ford 두 λŒ€μ˜ μ„œλ‘œ λ‹€λ₯Έ μžλ™μ°¨ 정보λ₯Ό μ €μž₯ν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨(ν•˜λ‚˜μ˜ named struct, μ—¬λŸ¬ μΈμŠ€ν„΄μŠ€). [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) A named struct used directly as a type, with no "struct" keyword needed at the declaration site (C++): ```cpp struct car { string brand; string model; int year; }; int main() { car myCar1; // no "struct" prefix needed myCar1.brand = "BMW"; myCar1.model = "X5"; myCar1.year = 1999; return 0; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.87 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Arrays RealLife]], [[CPP Enum]], [[C Structs]], [[C Typedef]] - **μ°Έμ‘° λ§₯락:** ꡬ쑰체 및 μ—΄κ±°ν˜• μ„Ήμ…˜ 첫 챕터 β€” μ—΄κ±°ν˜•(Enum) μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Structures (struct) β€” https://www.w3schools.com/cpp/cpp_structs.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Structures (struct)" page (Astra wiki-curation, P-Reinforce v3.1 format).