Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed nested namespace comment #23

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/namespaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ABC {
// ABC. The syntax for declaring a nested namespace is identical to the syntax of
// declaring a non-nested namespace.
namespace DEF {
// We define a function bar inside the N::M namespace.
// We define a function bar inside the ABC::DEF namespace.
void bar(float a) {
std::cout << "Hello from ABC::DEF::bar: " << a << std::endl;
}
Expand All @@ -46,18 +46,16 @@ namespace ABC {
}

// We define a function uses_spam in the ABC::DEF namespace. To refer to
// ABC::spam from the ABC::DEF namespace, we have no other option but to
// refer to it by its full identifier. Attempting to refer to it by spam
// will result in a compilation error, stating that no function called spam
// or ABC::DEF::spam exists. Note that it is possible to refer to every
// function by its full identifier, but doing this makes coding speed
// inefficient.
// ABC::spam from the ABC::DEF namespace, we can use spam(a). There is
// documentation governing the unqualified name lookup order on:
// https://en.cppreference.com/w/cpp/language/unqualified_lookup
// Note that it is possible to refer to every function by its full identifier,
// but doing this makes coding speed inefficient.
void uses_spam(int a) {
std::cout << "Hello from uses_spam: ";
ABC::spam(a);

// Try uncommenting this code, which calls spam(a), here.
// spam(a);
spam(a);
}
}

Expand Down