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

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

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/

相关文章:

c++ - 对循环范围的怀疑

ruby-on-rails - 在 Rails 助手的类中使用 link_to

c++ - 使用 `extern template` 防止模板类的隐式实例化

c++ - 链接期间出现 CUDA 多重定义错误

c++ - 是否可以在引发异常时记录异常?

css - 仅在一页上从类中删除样式?

jQuery 选择具有相同类的随机元素

c++ - 不理解左值的双重转发 - 按值传递时

c++ - 我如何根据它们的值获取 std::map 的前 n 个键?

c++ - 在 VLC/FFMPEG 或其他应用程序中接收 WebRTC