C++ "using tcp=x" 和 "namespace tcp=x" 有什么区别

C++ What's the difference between "using tcp=x" to "namespace tcp=x"

这两行代码有什么区别:

using tcp = boost::asio::ip::tcp;
namespace http = boost::beast::http;

例如:Boost Beast HTTP client example

区别在于using tcp=x为类型x创建了一个类型别名,而namespace tcp=x为命名空间x.[=14=创建了一个命名空间别名]

所以你不能在类型上使用命名空间别名,也不能在命名空间上使用类型别名。