Namespaces and Organization
Namespace Basics
A namespace groups related names so they do not crowd the global scope.
Namespace Basics
namespace_basics.cpp
#include <iostream>
namespace math_tools {
int doubleValue(int number) {
return number * 2;
}
}
int main() {
int value = ;
int result = math_tools::doubleValue(value);
std::cout << "value=" << value << std::endl;
std::cout << "result=" << result << std::endl;
return 0;
}
#include <iostream>
namespace math_tools {
int doubleValue(int number) {
return number * 2;
}
}
int main() {
int value = ;
int result = math_tools::doubleValue(value);
std::cout << "value=" << value << std::endl;
std::cout << "result=" << result << std::endl;
return 0;
}
#include <iostream>
namespace math_tools {
int doubleValue(int number) {
return number * 2;
}
}
int main() {
int value = ;
int result = math_tools::doubleValue(value);
std::cout << "value=" << value << std::endl;
std::cout << "result=" << result << std::endl;
return 0;
}
namespace
A namespace wraps functions, types, or variables inside a named group.