C++ keyword:
class
From cppreference.net
C++
C++ language
| General topics | ||||||||||||||||
| Flow control | ||||||||||||||||
| Conditional execution statements | ||||||||||||||||
| Iteration statements (loops) | ||||||||||||||||
|
||||||||||||||||
| Jump statements | ||||||||||||||||
| Functions | ||||||||||||||||
| Function declaration | ||||||||||||||||
| Lambda function expression | ||||||||||||||||
inline
specifier
|
||||||||||||||||
| Dynamic exception specifications ( until C++17* ) | ||||||||||||||||
noexcept
specifier
(C++11)
|
||||||||||||||||
| Exceptions | ||||||||||||||||
| Namespaces | ||||||||||||||||
| Types | ||||||||||||||||
| Specifiers | ||||||||||||||||
|
||||||||||||||||
| Storage duration specifiers | ||||||||||||||||
| Initialization | ||||||||||||||||
| Expressions | ||||||||||||||||
| Alternative representations | ||||||||||||||||
| Literals | ||||||||||||||||
| Boolean - Integer - Floating-point | ||||||||||||||||
| Character - String - nullptr (C++11) | ||||||||||||||||
| User-defined (C++11) | ||||||||||||||||
| Utilities | ||||||||||||||||
| Attributes (C++11) | ||||||||||||||||
| Types | ||||||||||||||||
typedef
declaration
|
||||||||||||||||
| Type alias declaration (C++11) | ||||||||||||||||
| Casts | ||||||||||||||||
| Memory allocation | ||||||||||||||||
| Classes | ||||||||||||||||
| Class-specific function properties | ||||||||||||||||
|
||||||||||||||||
| Special member functions | ||||||||||||||||
|
||||||||||||||||
| Templates | ||||||||||||||||
| Miscellaneous | ||||||||||||||||
Keywords
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Identifiers with special meaning | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
사용법
| (C++11부터) |
- 템플릿 선언 에서, class 은 타입 템플릿 매개변수 와 템플릿 템플릿 매개변수 를 선언하는 데 사용될 수 있습니다.
- 만약 함수나 변수가 클래스 타입과 동일한 이름으로 스코프 내에 존재하는 경우, class 을 이름 앞에 붙여 모호성을 해소할 수 있으며, 이는 정교화된 타입 지정자 를 생성합니다.
예제
이 코드 실행
class Foo; // 클래스의 전방 선언 class Bar // 클래스 정의 { public: Bar(int i) : m_i(i) {} private: int m_i; }; template<class T> // 템플릿 인자 void qux() { T t; } enum class Pub // 범위가 지정된 열거형, C++11부터 { b, d, p, q }; int main() { Bar Bar(1); // 변수 Bar가 타입 Bar를 가림 Bar Bar2(2); // 컴파일러 오류 class Bar Bar3(3); // 정교화된 타입 }
참고 항목
| (C++11부터) |
| (C++20부터) |