Page 2 of 2

Re: Noob question about scope.

Posted: November 1st, 2017, 9:39 pm
by albinopapa
static has a few meanings though, all stored in static memory, but in a function it's scope is still in the function. In class it's basically global, but can be hidden as a private member. In header, it is global, not sure why they say static is file scope when it can be seen and accessed by any translation unit that includes that header. Only way to get file scope is a global atop the cpp file.

I guess it also kind of depends on what you mean by scope. Where it can be accessed? Having to use the scope resolution operator (::) or when a destructor is called? If it's the last one, then namespace, file and static are all global since memory won't be freed and destructors won't be called until the program ends.