【发布时间】:2020-11-15 19:15:12
【问题描述】:
using 使标识符在全局范围内可见,但为什么不能用于static 类成员?
例如using std::string::size_type; 是错误的。为什么?
【问题讨论】:
标签: c++ class c++11 static using
using 使标识符在全局范围内可见,但为什么不能用于static 类成员?
例如using std::string::size_type; 是错误的。为什么?
【问题讨论】:
标签: c++ class c++11 static using
为什么不能用于
static类成员?
你误解了using-declaration的用法
Using-declarations 可用于将 命名空间成员引入 other namespaces and block scopes,或引入基类 成员到派生类定义中。
std::string::size_type; 是在std::string 类中定义的member type,而不是任何命名空间中的命名空间或函数。
因此,对于using,您只能指定/声明alias type for a type。例如:
using string_size_type = std::string::size_type;
【讨论】: