Tutorial by Examples

Unlike a named class or struct, unnamed classes and structs must be instantiated where they are defined, and cannot have constructors or destructors. struct { int foo; double bar; } foobar; foobar.foo = 5; foobar.bar = 4.0; class { int baz; public: int buzz; ...
As a non-standard extension to C++, common compilers allow the use of classes as anonymous members. struct Example { struct { int inner_b; }; int outer_b; //The anonymous struct's members are accessed as if members of the parent struct Example() : inner...
Unnamed class types may also be used when creating type aliases, i.e. via typedef and using: C++11 using vec2d = struct { float x; float y; }; typedef struct { float x; float y; } vec2d; vec2d pt; pt.x = 4.f; pt.y = 3.f;
Member names of an anonymous union belong to the scope of the union declaration an must be distinct to all other names of this scope. The example here has the same construction as example Anonymous Members using "struct" but is standard conform. struct Sample { union { int a...

Page 1 of 1