Skip to content
Learn Netverks

Lesson

Step 11/36 31% through track

namespaces

Namespaces

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Namespaces: the syntax, patterns, and safety habits you need before advancing in C++.

Teams still ship Namespaces in C++ codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Namespaces in contexts like: Game engines, trading systems, desktop apps, and performance-critical libraries.

Write C++ in main.cpp with int main(), click Run on server—the dev runner compiles with c++/g++ -std=c++17 -Wall and runs the binary; read template errors in stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Namespaces group names and prevent collisions. The standard library lives in std—hence std::vector, std::cout.

Using declarations

using std::cout;
cout << "Only cout imported\n";

namespace utils {
    int doubleValue(int x) { return x * 2; }
}

Avoid using namespace std; in headers—it pollutes every file that includes yours.

Important interview questions and answers

  1. Q: Why std:: prefix?
    A: Identifies standard library entities and avoids clashes with user code.
  2. Q: Anonymous namespaces?
    A: Give internal linkage to helpers in a .cpp file—like static at file scope.

Self-check

  1. Why avoid using namespace std in headers?
  2. What does namespace utils::doubleValue mean?

Pitfall: using namespace std; in headers causes name clashes for every includer—keep it in small .cpp files only if at all.

Interview prep

Why std:: prefix?

Identifies standard library entities and prevents name collisions with user code.

using namespace std in headers?

Discouraged—it injects all std names into every translation unit that includes the header.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • std namespace?
  • Anonymous ns?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump