RAD Studio
ContentsIndex
PreviousUpNext
C++ Scope

This section contains C++ Scope topics.

Name 
Description 
The lexical scoping rules for C++, apart from class scope, follow the general rules for C, with the proviso that C++, unlike C, permits both data and function declarations to appear wherever a statement might appear. The latter flexibility means that care is needed when interpreting such phrases as “enclosing scope” and “point of declaration.” 
The following rules apply to all names, including typedef names and class names, provided that C++ allows such names in the particular context discussed:
  • The name itself is tested for ambiguity. If no ambiguities are detected within its scope, the access sequence is initiated.
  • If no access control errors occur, the type of the object, function, class, typedef, and so on, is tested.
  • If the name is used outside any function and class, or is prefixed by the unary scope access operator ::, and if the name is not qualified by the binary :: operator or the member selection... more 
The name M of a member of a class X has class scope “local to X”; it can be used only in the following situations:
  • In member functions of X
  • In expressions such as x.M, where x is an object of X
  • In expressions such as xptr->M, where xptr is a pointer to an object of X
  • In expressions such as X::M or D::M, where D is a derived class of X
  • In forward references within the class of which it is a member
Names of functions declared as friends of X are not members of X; their names simply... more 
A name can be hidden by an explicit declaration of the same name in an enclosed block or in a class. A hidden class member is still accessible using the scope modifier with a class name: X::M. A hidden file scope (global) name can be referenced with the unary operator :: (for example, ::g). A class name X can be hidden by the name of an object, function, or enumerator declared within the scope of X, regardless of the order in which the names are declared. However, the hidden class name X can still be accessed by prefixing X with... more 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!