Small Project Organization
Namespace Helpers
A namespace groups helper names so a small project can avoid accidental collisions.
Namespace Helpers
namespace_helpers.cpp
#include <iostream>
namespace billing {
int addFee(int amount, int fee) {
return amount + fee;
}
}
int main() {
int subtotal = ;
int fee = 4;
int total = billing::addFee(subtotal, fee);
std::cout << "subtotal=" << subtotal << std::endl;
std::cout << "fee=" << fee << std::endl;
std::cout << "total=" << total << std::endl;
return 0;
}
#include <iostream>
namespace billing {
int addFee(int amount, int fee) {
return amount + fee;
}
}
int main() {
int subtotal = ;
int fee = 4;
int total = billing::addFee(subtotal, fee);
std::cout << "subtotal=" << subtotal << std::endl;
std::cout << "fee=" << fee << std::endl;
std::cout << "total=" << total << std::endl;
return 0;
}
#include <iostream>
namespace billing {
int addFee(int amount, int fee) {
return amount + fee;
}
}
int main() {
int subtotal = ;
int fee = 4;
int total = billing::addFee(subtotal, fee);
std::cout << "subtotal=" << subtotal << std::endl;
std::cout << "fee=" << fee << std::endl;
std::cout << "total=" << total << std::endl;
return 0;
}
namespace
Namespaces give related functions a shared prefix without putting everything into one global name pool.
qualification
Calling `billing::addFee` makes the helper's ownership visible at the call site.