Namespaces
Variants

C++ keyword: struct

From cppreference.net
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
constexpr (C++11)
consteval (C++20)
constinit (C++20)
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

사용법

(C++11부터)
  • 만약 함수나 변수가 비-공용체 클래스 타입의 이름과 동일한 이름으로 스코프 내에 존재하는 경우, struct 를 이름 앞에 붙여 명확하게 구분할 수 있으며, 이는 elaborated type specifier 를 생성합니다.

예제

struct Foo; // 구조체의 전방 선언
struct Bar  // 구조체 정의
{
    Bar(int i) : i(i + i) {}
    int i;
};
enum struct Pub // 범위가 지정된 열거형, C++11부터
{
    b, d, p, q,
};
int main()
{
    Bar Bar(1);
    struct Bar Bar2(2); // 정교화된 타입
}

참고 항목

(C++11부터)