The question is related to this answer , where it says:
In an unnamed class, it is not possible, for example, to declare constructors, destructors, operators that have a return type, or parameter types that include the name of the class.
You also, for example, cannot declare members of class data that are pointers or references to class objects.
In an unnamed class it is not allowed to declare static data members of the class.
However, if you try, then everything turns out to be somewhat wrong:
The variant with the argument is superfluous - I have not finished it yet.
But the return value and the static method obviously work.
#include <iostream> using namespace std; class { public: auto operator + () -> decltype(*this) { cout << "Unary plus\n"; return *this; } static void do_smth() { cout << "Static method\n"; } void test(auto obj) { cout << "Argument\n"; } } smth; int main() { +smth; decltype(smth) b; +b; decltype(b)::do_smth(); smth.test(b); return 0; } A static field is obtained only with -fpermissive , but it works -fpermissive :
http://melpon.org/wandbox/permlink/vuGA7yZvmS2ltLiM
#include <iostream> using namespace std; class { public: static int value; } smth; int decltype(smth)::value = 10; int main() { cout << decltype(smth)::value << endl; return 0; }