最初に、沼地標準の抽象UDT(ユーザー定義型)を使用します。
struct foo { virtual void f() = 0; }; // normal abstract type
foo obj;
// error: cannot declare variable 'obj' to be of abstract type 'foo'
また、UDTを定義すると同時にインスタンス化できることも思い出してください。
struct foo { foo() { cout << "!"; } }; // just a definition
struct foo { foo() { cout << "!"; } } instance; // so much more
// Output: "!"
例を組み合わせて、名前のない UDTを定義できることを思い出してください。
struct { virtual void f() = 0; } instance; // unnamed abstract type
// error: cannot declare variable 'instance' to be of abstract type '<anonymous struct>'
匿名のUDTに関する証明はもう必要ないため、純粋な仮想関数を失う可能性があります。また、名前instanceをfooに変更すると、次のようになります。
struct {} foo;
近づいて。
では、この匿名UDTが何らかのベースから派生したとしたらどうでしょうか。
struct bar {}; // base UDT
struct : bar {} foo; // anonymous derived UDT, and instance thereof
最後に、C ++ 11は拡張イニシャライザを導入しているため、次のような混乱を招く可能性があります。
int x{0};
この:
int x{};
そして最後に、これ:
struct : bar {} foo {};
これは、barから派生した名前のない構造体で、空の初期化子を使用してfooとしてインスタンス化されます。