C++ Namespaces
Namespaces prevent name collisions in large projects. The std namespace contains the entire standard library. You can create your own namespaces with the namespace keyword and access members with the :: scope resolution operator. Use using namespace sparingly to avoid ambiguity.
#include <iostream>
namespace Math {
int add(int a, int b) { return a + b; }
int multiply(int a, int b) { return a * b; }
}
int main() {
std::cout << Math::add(5, 3) << "\n";
std::cout << Math::multiply(4, 7);
return 0;
}
Try it Yourself โ