   Is this Standard C++ (local structs)
  hey i was wondering if the following is standard c++ or if it is some weird microsoft thing.#include <iostream>void DoStuff(){    int number = 10;    static int someNumber = 5;    // Q 1) is this standard c++?    struct AStruct // thats right struct    {   static void Print()   {  // strange compiler error if this is uncommented  // std::cout << number;   // but this works like a charm  std::cout << someNumber;  // Q 2) is the static works but non-static doesnt standard c++?   }    };    // and this works as well    AStruct::Print();}Edit: that compiles on VS 2005   
  Its standard. A static function has no this pointer so it can not access none static members.   ;Quote:Its standard. A static function has no this pointer so it can not access none static members.im not sure what that has to do with it or why that makes it standard, the code isnt trying to access a non-static member and even if i make the function non-static it still cant acess the non-static local variable in DoStuff() but can acess the static version.Edit:actualy i think you might have read it asstruct DoStuff // i.e. a STRUCT{    struct AStruct // with a nested struct definition    { };};instead ofvoid DoStuff() // i.e. a FUNCTION{    struct AStruct // with a nested struct definition    { };};;  Having the struct is standard.What the AP is saying is a bit confused, though. this-pointers are only relevant for looking up members of the struct, and 'number' is something in an enclosing scope. I don't know why you're allowed to "close over" static but not non-static variables in that way. I assume closing over statics is for consistency with the ability to use globals from member functions, and I assume not closing over locals is because of "internal vs. external linkage" issues.   ;  "actualy i think you might have read it as"Well I have to admit Ive only just woken up and didn't look at that correctly at all. I saw it as a static function inside a struct. OOPs.   ;  thanks   ;  Well, the address of a local static variable is resolvable at compile time, so accessing one works just like accessing a global static variable. Local automatic variables, however, are allocated on the stack so their address may vary. The compiler would have to generate code to pass the variables as hidden extra parameters to the function.   ;  Well, for my two cents, it compiles on MinGW. (Even though this has already been solved).Interesting, though. Never knew this.   