为什么`using`关键字不能用于静态类成员?

时间:2020-07-26 10:04:09

标签: c++ class c++11 static using

using使标识符在全局范围内可见,但为什么不能用于static类成员?

例如using std::string::size_type;是错误的。为什么?

1 个答案:

答案 0 :(得分:3)

为什么不能用于static类成员?

您误解了using-declaration

的使用

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;