1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-10 16:54:33 +02:00

Update C++ docs to improve clarity on namespace.

Make it immediately obvious what importing a namespace does, instead of just listing how to use fully qualified symbols.
This commit is contained in:
bharathcs
2022-08-29 13:13:34 +08:00
committed by GitHub
parent e6f2e1420c
commit 5faaf058e1

View File

@@ -158,6 +158,10 @@ namespace Second {
{
printf("This is Second::foo\n");
}
void bar()
{
printf("This is Second::bar\n");
}
}
void foo()
@@ -168,10 +172,12 @@ void foo()
int main()
{
// Includes all symbols from namespace Second into the current scope. Note
// that simply foo() no longer works, since it is now ambiguous whether
// we're calling the foo in namespace Second or the top level.
// that while bar() works, simply using foo() no longer works, since it is
// now ambiguous whether we're calling the foo in namespace Second or the
// top level.
using namespace Second;
bar(); // prints "This is Second::bar"
Second::foo(); // prints "This is Second::foo"
First::Nested::foo(); // prints "This is First::Nested::foo"
::foo(); // prints "This is global foo"