File: referring.yo

package info (click to toggle)
c%2B%2B-annotations 8.2.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,804 kB
  • ctags: 2,845
  • sloc: cpp: 15,418; makefile: 2,473; ansic: 165; perl: 90; sh: 29
file content (53 lines) | stat: -rw-r--r-- 2,144 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Given a namespace and its entities, the i(scope resolution operator) can be
used to refer to its entities. For example, the function tt(cos())
defined in the tt(CppAnnotations) namespace may be used as follows:
        verb(
    // assume CppAnnotations namespace is declared in the
    // following header file:
    #include <cppannotations>

    int main()
    {
        cout << "The cosine of 60 degrees is: " <<
                CppAnnotations::cos(60) << '\n';
    }
        )
    This is a rather cumbersome way to refer to the tt(cos()) function in the
tt(CppAnnotations) namespace, especially so if the function is frequently
used. In cases like these an em(abbreviated) form can be
used after specifying a emi(using declaration). Following
        verb(
    using CppAnnotations::cos;  // note: no function prototype,
                                // just the name of the entity
                                // is required.
        )
    calling tt(cos) will call the tt(cos) function defined in the
tt(CppAnnotations) namespace. This implies that the standard tt(cos)
function, accepting radians, is not automatically called anymore. To call that
latter tt(cos) function the plain
scope resolution operator should be used:
        verb(
    int main()
    {
        using CppAnnotations::cos;
        ...
        cout << cos(60)         // calls CppAnnotations::cos()
            << ::cos(1.5)       // call the standard cos() function
            << '\n';
    }
        )
    A tt(using) declaration can have restricted scope. It can be used inside a
block. The tt(using) declaration prevents the definition of entities having
the same name as the one used in the tt(using) declaration. It is not possible
to specify a tt(using) declaration for a variable tt(value) in some namespace,
and to define (or declare) an identically named object in a block also
containing a tt(using) declaration. Example:
        verb(
    int main()
    {
        using CppAnnotations::value;
        ...
        cout << value << '\n';  // uses CppAnnotations::value
        int value;              // error: value already declared.
    }
        )