Namespaces
Variants

class property specifiers (since C++26)

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

클래스가 대체 가능함(replaceable)  ( replaceable_if_eligible ), 사소하게 재배치 가능함(trivially relocatable)  ( trivially_relocatable_if_eligible )을 지정하거나, 클래스가 파생될 수 없음 ( final )을 지정합니다.

목차

구문

클래스 속성 지정자 는 클래스 정의의 시작 부분, 클래스 이름 바로 뒤에 나타나며 클래스 선언에서는 나타날 수 없습니다.

class-key attr  (선택 사항) class-head-name class-prop-specifier-seq  (선택 사항) base-clause  (선택 사항)
class-prop-specifier-seq - 하나 이상의 class-prop-specifier 들로 구성되지만, 각각은 최대 한 번만 나타날 수 있습니다.
class-prop-specifier - 다음 중 하나: final , replaceable_if_eligible trivially_relocatable_if_eligible .

이전에는 (C++26) , class-prop-specifier-seq  (optional) 대신 class-virt-specifier  (optional) 가 있었으며, 이는 final 지정자 (C++11부터) 에 대한 final 만 허용했습니다.

설명

final , replaceable_if_eligible 그리고 trivially_relocatable_if_eligible 는 클래스 헤드에서 사용될 때 특별한 의미를 갖는 식별자입니다. 다른 문맥에서는 예약어가 아니며 객체와 함수의 이름으로 사용될 수 있습니다.

final 지정자

final 는 이 클래스가 다른 클래스 정의의 base-specifier-list 에 나타날 수 없음을 지정합니다(즉, 상속될 수 없음). 그렇지 않으면 프로그램이 올바르지 않게 형성됩니다(컴파일 타임 오류가 발생함). final union 정의와 함께 사용될 수도 있으며, 이 경우 ( std::is_final 의 결과에 영향을 미치는 것 외에는) (C++14부터) 효과가 없습니다. 왜냐하면 union은 상속될 수 없기 때문입니다.

replaceable_if_eligible 지정자

replaceable_if_eligible 는 이 클래스가 교체 가능한  경우에만 교체 자격이 있는  것을 지정합니다.

trivially_relocatable_if_eligible 지정자

trivially_relocatable_if_eligible 는 이 클래스가 사소하게 재배치 가능  할 경우 사소한 재배치 적격  임을 지정합니다.

대체 가능성

클래스 C replaceable  하려면, 해당 클래스가 eligible for replacement  이어야 하며 다음 중 하나를 만족해야 합니다:

교체 자격 요건

클래스 C 는 다음 중 하나에 해당하지 않는 한 교체 가능 합니다:

단순 재배치 가능성

클래스는 trivially relocatable  합니다 만약 그것이 eligible for trivial relocation  하고 다음 중 하나를 만족하는 경우:

사소한 재배치의 적격성

클래스는 다음 중 하나를 가지지 않는 한 사소한 재배치에 적합합니다 :

단, 하나 이상의 다형적 클래스 타입 서브객체를 갖는 그 외의 조건을 충족하는 union trivial relocation이 가능한지 여부는 구현에 따라 정의된다 .

기본 이동 가능성

클래스 C 가 다음의 모든 조건을 만족할 경우 기본 이동 가능(default movable)  합니다:

  • C 타입의 객체를 C 타입의 직접 초기화(direct-initializing) 할 때의 오버로드 해결(overload resolution)은 C 의 직접 멤버이며 사용자 제공(user-provided)되지도 않고 삭제된(deleted) 것도 아닌 생성자를 선택합니다.
  • C 타입의 lvalue C 타입의 xvalue 를 할당할 때의 오버로드 해결(overload resolution)은 C 의 직접 멤버이며 사용자 제공(user-provided)되지도 않고 삭제된(deleted) 것도 아닌 대입 연산자 함수를 선택합니다.
  • C 는 사용자 제공(user-provided)되지도 않고 삭제된(deleted) 것도 아닌 소멸자(destructor) 를 가집니다.

키워드

final , replaceable_if_eligible , trivially_relocatable_if_eligible .

참고

기능 테스트 매크로 표준 기능
__cpp_trivial_relocatability 202502L (C++26) Trivial relocatability

예제

struct final;      // OK; 'final'이라는 이름의 클래스를 선언하며,
                   // 클래스 속성 지정자를 사용하지 않음.
struct IF final;   // 잘못된 형식: 클래스 속성 지정자는
                   // 함수 선언에서 나타날 수 없음.
struct F final {}; // OK; 지정자가 클래스 F를 파생 불가로 표시함.
struct D: F {};    // 잘못된 형식: 클래스 F로부터 파생될 수 없음.
// OK; 지정자가 조건부로 적합할 경우 클래스 R을 𝘳𝘦𝘱𝘭𝘢𝘤𝘦𝘢𝘣𝘭𝘦로 표시함.
struct R replaceable_if_eligible {};
// OK; 지정자가 조건부로 적합할 경우 클래스 T를 𝘵𝘳𝘪𝘷𝘪𝘢𝘭𝘭𝘺 𝘳𝘦𝘭𝘰𝘤𝘢𝘵𝘢𝘣𝘭𝘦로 표시함.
struct T trivially_relocatable_if_eligible {};
// OK; 클래스는 여러 클래스 속성 지정자로 표시될 수 있음.
struct FRT final replaceable_if_eligible trivially_relocatable_if_eligible {};
// 잘못된 형식: 각 클래스 속성 지정자는 최대 한 번만 나타날 수 있음.
struct FRF final replaceable_if_eligible final {};
int main() {}

참조문헌

  • C++26 표준 (ISO/IEC 14882:2026):
  • 6.8.1 Trivially relocatable and replaceable types [basic.types.general]

참고 항목

final 지정자 (C++11) 메서드가 재정의되거나 클래스가 파생되는 것을 금지함을 선언
(C++14)
타입이 final 클래스 타입인지 확인
(클래스 템플릿)