我正在查看两个源代码。一个使用这个:
using boost::property_tree::ptree;
另一个使用这个:
namespace ptree = boost::property_tree::ptree;
有什么区别?
最佳答案
与
using boost::property_tree::ptree;
您将 boost::property_tree::ptree
类拉入当前命名空间。从那时起,您可以使用 ptree
而不是 boost::property_tree::ptree
。
与
namespace ptree = boost::property_tree::ptree;
你应该有一个错误,因为 boost::property_tree::ptree
是一个类 而不是一个命名空间。否则(如果它是一个命名空间)它将为命名空间创建一个别名(就像 pt
在 Boost property tree tutorials 中的使用方式)。
关于c++命名空间和using有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43516855/