Namespaces (::)
namespace::feature()
#include <iostream>
// Define a namespace called 'First'
namespace First {
// Inside this namespace, we define a function 'display'
void display() {
std::cout << "This is the First namespace." << std::endl;
}
}
// Define another namespace called 'Second'
namespace Second {
// Inside this namespace, we define another function 'display'
void display() {
std::cout << "This is the Second namespace." << std::endl;
}
}
int main() {
// Call the 'display' function from the 'First' namespace
First::display();
// Call the 'display' function from the 'Second' namespace
Second::display();
return 0;
}Didn't Understand What was Written Above?
Teams Contributed to this Article:
Last updated
Was this helpful?
