10.5. Name Lookup and Scoping

The fully-qualified identifier names and name lookup rules are similar to C++. Because the IDL has no using directive, no overriding and the IDL ignores class inheritance when performing a name lookup, the actual rules are much simplier.

Each identifier has exactly one global name, usually called fully-qualified identifier name. It's constructed by separating list of scope identifiers the identifier is defined in, beginning at the root scope, by ::, and prepending :: to this name. Identifiers of the following elements introduce a new scope:

[Note]Note

In C++, fully-qualified name of enumerants defined within an enumeration type does not include the identifier of the enumeration type. In IDL it does.

The following example shows definitions of several identifiers and their fully-qualified names in comments:

/* root scope */

/* namespace ::foo */
namespace foo {

/* class ::foo::Bar */
class Bar
    {
    /* class ::foo::Bar::Baz */
    class Baz
        {
        }

    /* enum ::foo::Bar::MyEnum */
    enum MyEnum
        {
        /* enumerant ::foo::Bar::MyEnum::NUMBER */
        NUMBER = 1,
        }
    }

/* class ::foo::Bar2 */
class Bar2 : Bar
    {
    }

}

Unlike C++, inheritance in the IDL does not introduce new global identifier names for the inherited identifiers. Therefore ::foo::Bar2::Baz is not a name of ::foo::Bar::Baz and can't be used to refer to it.

The IDL has a single namespace for all identifiers within a given scope. You can't declare multiple identifiers with the same name in the same scope, even if their entity type is different.

The name lookup rules are really simple. You can refer to an identifier either using its fully-qualified name, a qualified name (<scope-name>::<identifier>), or just a literal. If the name begins with ::, it's a fully-qualified name, which is an unique identification of an identifier in IDL, and the name resolution is obvious. Otherwise the name resolution starts at current scope. If concatenation of fully-qualified name of the current scope, :: and the name yields a fully-qualified name of an existing identifier, the name resultion successfully stops at the identifier. Otherwise the same rule is applied to the parent scope of the current scope, and so on, until the identifier is found, or the root scope is reached without a success.