using
使标识符在全局范围内可见,但为什么不能用于static
类成员?
例如using std::string::size_type;
是错误的。为什么?
答案 0 :(得分:3)
的使用为什么不能用于
static
类成员?
Using
-声明可用于将命名空间成员引入 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;