From e25732ff9e4f6bcaa55055a2d409d0309445a818 Mon Sep 17 00:00:00 2001 From: Raunaq Pahwa Date: Wed, 4 Sep 2024 00:23:18 -0400 Subject: [PATCH 1/3] Fixed nested namespace comment --- src/namespaces.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/namespaces.cpp b/src/namespaces.cpp index 3f26274..586785d 100644 --- a/src/namespaces.cpp +++ b/src/namespaces.cpp @@ -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; } From ca2a292f73c034231d3cec374ff8d7c20e8275e4 Mon Sep 17 00:00:00 2001 From: Raunaq Pahwa Date: Wed, 4 Sep 2024 00:50:49 -0400 Subject: [PATCH 2/3] Changed comment for unqualified name lookup --- src/namespaces.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/namespaces.cpp b/src/namespaces.cpp index 586785d..09ee0f2 100644 --- a/src/namespaces.cpp +++ b/src/namespaces.cpp @@ -36,6 +36,10 @@ namespace ABC { std::cout << "Hello from ABC::DEF::bar: " << a << std::endl; } + void spam(int a) { + std::cout << "Hello from ABC::DEF::spam: " << a << std::endl; + } + // We define a function uses_bar inside the ABC::DEF namespace. However, since // bar is in the same namespace as uses_bar (they're both in the ABC::DEF // namespace), the function bar is just referred to by its name in the @@ -46,18 +50,17 @@ 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 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); } } From 4fcb476aaf45b973215b05926b3d5b1de5921fe0 Mon Sep 17 00:00:00 2001 From: Raunaq Pahwa Date: Wed, 4 Sep 2024 01:05:48 -0400 Subject: [PATCH 3/3] Removed the uncomment this code line --- src/namespaces.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/namespaces.cpp b/src/namespaces.cpp index 09ee0f2..186b4db 100644 --- a/src/namespaces.cpp +++ b/src/namespaces.cpp @@ -36,10 +36,6 @@ namespace ABC { std::cout << "Hello from ABC::DEF::bar: " << a << std::endl; } - void spam(int a) { - std::cout << "Hello from ABC::DEF::spam: " << a << std::endl; - } - // We define a function uses_bar inside the ABC::DEF namespace. However, since // bar is in the same namespace as uses_bar (they're both in the ABC::DEF // namespace), the function bar is just referred to by its name in the @@ -51,7 +47,7 @@ namespace ABC { // We define a function uses_spam in the ABC::DEF namespace. To refer to // ABC::spam from the ABC::DEF namespace, we can use spam(a). There is - // documentation governing the unqualified lookup order on: + // 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. @@ -59,7 +55,6 @@ namespace ABC { std::cout << "Hello from uses_spam: "; ABC::spam(a); - // Try uncommenting this code, which calls spam(a), here. spam(a); } }