Files
2nd/10_Wiki/Topics/Topic_Programming/Topic_CPP/CPP_Auto.md
T
Antigravity Agent 9a135bd19d docs(10_Wiki): Topic_Business/General/Graphic/Programming을 Topics/ 하위로 이동
최상위 10_Wiki/Topic_*였던 4개 카테고리 폴더를 10_Wiki/Topics/Topic_* 로 재배치.
콘텐츠 변경 없음(순수 폴더 이동) — Topics/ 하위 나머지 폴더는 이미 지난 커밋에서
전부 정리된 상태(잔존 항목은 에이전트 운영 상태 및 사용자가 보존을 요청한
업데이트0615/무제 3.canvas 뿐).
2026-07-05 00:44:01 +09:00

5.1 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
cpp-auto C++ auto Programming_Language draft conceptual
auto keyword C++
type inference C++
C++ 자동 타입 추론
B 0.86 2026-07-04 2026-07-04
cpp
programming-language
w3schools
auto
type-inference
https://www.w3schools.com/cpp/cpp_auto.asp

CPP Auto

🎯 한 줄 통찰 (One-line insight)

C++11's auto hijacks the EXACT SAME keyword C already had (auto is a legal C storage-class specifier meaning "automatic/local storage duration," the implicit default for every local variable) and repurposes it to mean something completely unrelated — compile-time type inference — meaning any C programmer who ever learned "auto is the default, mostly-unused storage class" must unlearn that and relearn auto as "let the compiler deduce my type," the same token now doing a categorically different job depending on which language's rules apply. [S1]

🧠 핵심 개념 (Core concepts)

  • auto = compile-time type inference — the compiler determines the variable's type from the value assigned to it, e.g. auto x = 5; makes x an int. [S1]
  • Must initialize at declarationauto x; with no assigned value is illegal; the compiler needs the right-hand value to infer a type from. [S1]
  • Type is locked in after inference — once auto x = 5; fixes x as int, later reassigning a different type (x = 9.99;) is a compile error, exactly as if int had been written explicitly. [S1]
  • Works for any typeint, float (5.99f), double (9.98), char ('D'), bool (true), and std::string (string("Hello")) are all shown inferred correctly. [S1]
  • Primary real-world use: complex types — the tutorial notes auto is used sparingly for simple types (int, double) but becomes genuinely valuable for verbose/complex types like iterators and lambdas, where writing the full type out by hand is impractical. [S1]

📖 세부 내용 (Details)

  • Basic substitution: auto x = 5; behaves identically to int x = 5;. [S1]
  • Multi-type example: auto myNum = 5; auto myFloatNum = 5.99f; auto myDoubleNum = 9.98; auto myLetter = 'D'; auto myBoolean = true; auto myString = string("Hello"); — each variable's true type is silently inferred (int, float, double, char, bool, std::string respectively). [S1]
  • Type-locking demonstrated: auto x = 5; x = 10; // OK; x = 9.99; // Error. [S1]
  • Cross-reference to prior chapters: this page explicitly calls back to iterators (vector<string>::iterator it shortened to auto it) and forward to lambdas as the chapters where auto's real value shows up. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • 동일 키워드, 완전히 다른 의미: C에서 auto는 지역 변수의 기본 저장 기간(automatic storage duration)을 명시하는 저장 클래스 지정자로, 사실상 거의 사용되지 않는 키워드였다. C++11은 이 키워드를 재사용하되 "타입 추론"이라는 전혀 다른 의미를 부여했다는 점이 이번 챕터에서 확인됨 — 문법 토큰은 같지만 역할은 완전히 별개. [S1]
  • 한 번 추론된 타입은 고정됨: 동적 타입 언어의 변수 재할당과 혼동하기 쉽지만, auto로 추론된 타입도 일반 int/double 변수와 똑같이 정적 타입 검사를 받는다는 점이 예제(x = 9.99; 에러)로 명확히 확인됨. [S1]

🛠️ 적용 사례 (Applied in summary)

Iterators 챕터에서 이미 vector<string>::iterator it 대신 auto it = cars.begin();으로 축약해 사용한 것이 auto의 실전 활용 사례로 원문에서 직접 역참조됨. [S1]

💻 코드 패턴 (Code patterns)

Type inference across multiple types, and the type-locking rule (C++):

auto myNum = 5;              // int
auto myFloatNum = 5.99f;     // float
auto myDoubleNum = 9.98;     // double
auto myLetter = 'D';         // char
auto myBoolean = true;       // bool
auto myString = string("Hello"); // std::string

auto x = 5;   // x is now an int
x = 10;       // OK - still an int
x = 9.99;     // Error - can't assign a double to an int

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.86
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C++ auto" page (Astra wiki-curation, P-Reinforce v3.1 format).