Namespaces
Variants
Actions

C++ keyword: struct

From cppreference.com
< cpp‎ | keyword
 
 
C++ language
General topics
Conditional execution statements
Iteration statements (loops)
Jump statements
Exceptions
Namespaces
Types
Specifiers
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
Casts
Memory allocation
Class-specific function properties
Special member functions
Miscellaneous
 
Keywords
Identifiers with special meaning
(C++11)
(C++20)
(C++20)
(C++11)
(C++26)
(C++26)
 

[edit] Usage

  • If a function or a variable exists in scope with the name identical to the name of a non-union class type, struct can be prepended to the name for disambiguation, resulting in an elaborated type specifier.

[edit] Example

Run this code
struct Foo; // forward declaration of a struct
 
struct Bar // definition of a struct
{
 Bar(int i) : i(i + i) {}
 
 int i;
};
 
enum struct Pub // scoped enum, since C++11
{
 b, d, p, q,
};
 
int main()
{
 Bar Bar(1);
 struct Bar Bar2(2); // elaborated type
}

[edit] See also

(since C++11)
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/keyword/struct&oldid=176065"

AltStyle によって変換されたページ (->オリジナル) /