Talk:cpp/language/nested types
[edit] C++11 changes?
I'm pretty sure that C++11 changed the rules for nested classes slightly. Specifically, I recall that nested classes are now considered a first-class member of their outer class, so they can access private and protected data members of their enclosing class and can be declared/defined in any order. Can this be confirmed and updated? LB(T|C) 13:01, 28 March 2014 (PDT)
- Yes, I missed the small change in 9.5/1 from 03 to 11. Updated (changes weren't that drastic though, you could always access private members) --Cubbi (talk) 14:17, 28 March 2014 (PDT)
[edit] As there are two Xes.
As of 20 Apr 2014 there is such a code snippet on the page:
int x,y; // globals class enclose { // enclosing class int x; // note: private members static int s; public: struct inner { // nested class void f(int i) { x = i; // Error: can't write to non-static enclose::x without instance int a = sizeof x; // Error until C++11, // OK in C++11: operand of sizeof is unevaluated, this use is ok ... };
It raise a question about the value of a:
- In the statement a get size of a private member or of the global x?
Would it be better to make global x and private x of different types and add the actual value of a in the comments, wouldn't it?
- I added a comment to say which x is found by lookup at that line, although it isn't different from one line above. --Cubbi (talk) 12:55, 20 April 2014 (PDT)
[edit] Is the current title appropriate?
It seems that nested class is better than nested types, as nested types can also be nested typedef's, but this page doesn't talk anything about that. --115.231.76.49 08:17, 17 May 2014 (PDT)