I've recently begun reading the "dragon book" (Compilers: Principles, Techniques, and Tools - Wikipedia, the free encyclopedia) and where the authors mentions scope they say this:
But I don't understand what they mean by using public/protected/private to control the scope and I can't find an explanation for it in the book.Quote:
Most languages, including C and its family, use static scope. The scope rules for C are based on program structure; the scope of a declaration is determined implicitly by where the declaration appears in the program. Later languages, such as C++, Java, and C#, also provide explicit control over scopes through the use of keywords like public, private, and protected.
Consider the following code:
Now, I obviously can't access j outside of A. But both i and j have the same lifetime, and I've been taught that scope and lifetime are basically just different words for the same thing.Code:
a.i = 0; // valid
a.j = 0; // illegal
Is there something I'm missing here?