Category

Namespaces

Why Namespaces Exist (Name Collisions)

A namespace is a named space in a program, containing a group of related identifiers (functions, variables, types, etc.). Everything that is declared inside a n…

Aug 19, 2026 →

Declaring and Defining Namespaces

The simplest way to create a namespace is to simply write down the keyword namespace, give it a name, and then open a pair of curly braces. Everything declared…

Aug 19, 2026 →

Nested Namespaces

Sometimes one namespace isn’t enough. You create a very broad namespace like Graphics, but then you start creating code for drawing, color management, and matri…

Aug 19, 2026 →

using Declarations

Typing the fully qualified name all the time soon gets boring. After a few calls to Graphics::Color::setRed or Company::Project::Utils::add, the repeated prefix…

Aug 19, 2026 →

using Directives

A using directive is the overbearing cousin of a using declaration. The declaration pulls in one well chosen name; the directive, every name to be found within…

Aug 19, 2026 →

Namespace Aliases

Long nested names are correct, but they are also tiring to type and tiring to read. When the call looks like Company::Graphics::Rendering::Shaders::load(), then…

Aug 19, 2026 →

Unnamed (Anonymous) Namespaces

Occasionally, you may require a name that belongs strictly within a single file and must never be made accessible to any other files. A global function or varia…

Aug 19, 2026 →

The Global Namespace

Every name within a C++ program must live somewhere. When a function or variable is written and not included within some namespace declaration block, it does no…

Aug 19, 2026 →

Why using namespace std; Should Be Avoided

One line can discreetly decide how many names qualify a search for each proceeding name. That line is using namespace std;. It's a simple and innocent line that…

Aug 19, 2026 →
About CppLearn

CppLearn is an interactive, free reference for modern C++. In each lesson, you'll find out how the language works, rather than just lines of code that you can copy and paste. We cover concepts starting from beginner lessons on fundamentals and proceed to templates, move semantics, smart pointers, and areas that usually trap or scare C++ learners.