Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
Imagine that namespace is something like "This code is part of my module!". It helps to avoid naming conflicts. For example, I created library which has function "fun". You also created library that has function "fun". Now if we try to use my and yours library, we wil figure out that our compiler has no idea which function to use and it just does not compile. But we have plan how to make our libraries compatible. Here comes the namespace! :D Now my code uses namespace "ag", and yours uses namespace "vvd". So we can call my function by "ag::fun()", and yours by using "vvd::fun()". This will compile, and users of our libraries will be finaly happy. Now what is std? Well, its namespace of standard libraries. We really don't want to collide with standard identifiers. So the standard things use std namespace. Sometimes we are tired of writing everywhere "std::cout", so we use "using namespace std" to notify compiler that we are tired of explicitly specifying std:: everywhere.
2nd Jan 2020, 9:50 PM
Null
Null - avatar