The declaration of a non-inline static data member in its class definition is not a definition and may be of an incomplete type other than cv
void
. ...
That means, this is a valid code:
#include <iostream>
struct S
{
static S s;
};
S S::s;
int main()
{
std::cout << &(S::s) << '\n';
std::cout << &(S::S::s) << '\n';
}
The snippet above prints the same address for &(S::s)
and &(S::S::s)
.
What is the reason for allowing such a construction in C++?