Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Standard seems to support (the snippet below compiles) a static data member having the same type as the class itself [duplicate]

Where specifically is this covered in the Standard? I found §9.2/10: Non-static (9.4) data members shall not have incomplete types. In particular, a class C shall not contain a non-static member of class C, but it can contain a pointer or reference to an object of class C., but this doesn't seem to directly support the issue at hand.

#include <iostream>
struct A{
    int i;
    static A a;
};

A A::a{10};

int main() {
    std::cout << A::a.i << '\n';
}
like image 609
Wake up Brazil Avatar asked Mar 20 '14 13:03

Wake up Brazil


1 Answers

C++11 9.4.2/2:

The declaration of a static data member in its class definition is not a definition and may be of an incomplete type other than cv-qualified void.

like image 165
Mike Seymour Avatar answered Sep 22 '22 23:09

Mike Seymour