course content

Course Content

Introduction to C++

Namespace Namespace

Imagine you work as a C++ developer at a startup, and you and a colleague mistakenly created a function with the same name as yours in a shared project.

Your programs are not compatible, the processor doesn't understand what specific function you want to call.

Don't worry. Functions will be covered later in this course!

To avoid name conflicts, you and your colleague need to create your own namespaces. The namespace allows you to create your repository with your names for objects that will not conflict with the same object names from other repositories.


Repository is a storage place.

Consider an example with the same functions:

This example throws an error. This is done on purpose.



In this case, we will get an error, because the compiler does not know which function to call: yours or your colleague's.

But if we wrap the functions in their own namespaces, then:



The compiler understands that we want to call the function someFunction() from the namespace with the name myNameSpace, and executes this command without any problems. The code will work, and we will get the "This is my function!" message.

Section 1.

Chapter 4