using
使标识符在全局范围内可见,但是为什么不能将其用于static
类成员呢?
例如using std::string::size_type;
是错误的。为什么?
最佳答案
Why cannot be used for
static
class member?
您误解了
using
-declaration的用法
Using
-declarations can be used to introduce namespace members into other namespaces and block scopes, or to introduce a base class members into derived class definitions.
std::string::size_type;
是在std::string
类中定义的member type,而不是任何 namespace 中的 namespace 或函数。因此,使用
using
,您只能指定/声明alias type for a type。例如:using string_size_type = std::string::size_type;
关于c++ - 为什么 `using`关键字不能用于静态类成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63098687/