Namespaces and Organization
Qualified Names
The :: operator chooses a name from a specific namespace.
Qualified Names
qualified_names.cpp
#include <iostream>
#include <string>
namespace checkout {
std::string status(int cents) {
if (cents >= 1000) {
return "large";
}
return "small";
}
}
int main() {
int totalCents = ;
std::string size = checkout::status(totalCents);
std::cout << "totalCents=" << totalCents << std::endl;
std::cout << "status=" << size << std::endl;
return 0;
}
#include <iostream>
#include <string>
namespace checkout {
std::string status(int cents) {
if (cents >= 1000) {
return "large";
}
return "small";
}
}
int main() {
int totalCents = ;
std::string size = checkout::status(totalCents);
std::cout << "totalCents=" << totalCents << std::endl;
std::cout << "status=" << size << std::endl;
return 0;
}
#include <iostream>
#include <string>
namespace checkout {
std::string status(int cents) {
if (cents >= 1000) {
return "large";
}
return "small";
}
}
int main() {
int totalCents = ;
std::string size = checkout::status(totalCents);
std::cout << "totalCents=" << totalCents << std::endl;
std::cout << "status=" << size << std::endl;
return 0;
}
qualified name
A qualified name includes the namespace, `::`, and the name to use.