Namespaces and Organization
Using Declarations
A using declaration brings one selected name from a namespace into the current scope.
Using Declarations
using_declarations.cpp
#include <iostream>
#include <string>
namespace greetings {
std::string hello(const std::string& name) {
return "Hello, " + name;
}
}
int main() {
using greetings::hello;
std::string name = ;
std::string message = hello(name);
std::cout << "name=" << name << std::endl;
std::cout << "message=" << message << std::endl;
return 0;
}
#include <iostream>
#include <string>
namespace greetings {
std::string hello(const std::string& name) {
return "Hello, " + name;
}
}
int main() {
using greetings::hello;
std::string name = ;
std::string message = hello(name);
std::cout << "name=" << name << std::endl;
std::cout << "message=" << message << std::endl;
return 0;
}
#include <iostream>
#include <string>
namespace greetings {
std::string hello(const std::string& name) {
return "Hello, " + name;
}
}
int main() {
using greetings::hello;
std::string name = ;
std::string message = hello(name);
std::cout << "name=" << name << std::endl;
std::cout << "message=" << message << std::endl;
return 0;
}
using declaration
A using declaration names exactly what should be brought into the current scope.