AlgoMaster Logo

Namespaces Basics

Last Updated: June 6, 2026

Medium Priority
20 min read

A namespace is a named scope that groups related identifiers (functions, classes, variables, constants) so they don't collide with identically named identifiers from other parts of a program. C++98 introduced namespaces to solve a practical problem: once a codebase reaches a few thousand lines, or starts pulling in libraries from different authors, the chance of two files declaring a Cart class or a total() function approaches one. This chapter covers why namespaces exist, how to declare one, how the scope resolution operator :: reaches into them, why std is the namespace encountered first, and how to split a namespace's declarations and definitions across header and source files.

Premium Content

Subscribe to unlock full access to this content and more premium articles.