FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [View Raw Code]   [Original HTTPS Page]

cppfront/docs/cpp2/namespaces.md at main · helmesjo/cppfront · GitHub

forked from hsutter/cppfront

Latest commit

 

History

History
60 lines (42 loc) · 1.4 KB

File metadata and controls

60 lines (42 loc) · 1.4 KB

Namespaces

Overview

A namespace N can contain declarations that are then accessed by writing N:: or using the namespace or declaration. For example:

//  A namespace to put all the names provided by a widget library
widgetlib: namespace = {
    widget: type = { /*...*/ }
    // ... more things ...
}

main: () = {
    w: widgetlib::widget = /*...*/;
}

using

A #!cpp using statement brings names declared in another namespace into the current scope as if they had been declared in the current scope. It has two forms:

  • #!cpp using a_namespace::a_name; brings the single name a_name into scope.

  • #!cpp using namespace a_namespace; brings all the namespace's names into scope.

For example:

//  A namespace to put all the names provided by a widget library
widgetlib: namespace = {
    widget: type = { /*...*/ }
    // ... more things ...
}

main: () = {
    //  Explicit name qualification
    w: widgetlib::widget = /*...*/;

    {
        //  Using the name, no qualification needed
        using widgetlib::widget;
        w2: widget = /*...*/;
        // ...
    }

    {
        //  Using the whole namespace, no qualification needed
        using namespace widgetlib;
        w3: widget = /*...*/;
        // ...
    }

    // ...
}

Back | FazBrowse Home | New Git URL