c++ - 本地类、内部类和嵌套类在C++中是一回事吗?

标签 c++ inner-classes nested-class local-class

Local class、Inner class 和 Nested class 在 C++ 中是同一个意思吗?

最佳答案

本地类和嵌套类是不同的野兽。

嵌套类是在另一个类的范围内声明的类。

本地类在函数定义中声明。

内部类是一个非标准的C++术语,所以我不确定如何定义它。


嵌套类:

IBM 文档作为一个很好的文档 here .
总结:

  • The name of a nested class is local to its enclosing class. Unless you use explicit pointers, references, or object names, declarations in a nested class can only use visible constructs, including type names, static members, and enumerators from the enclosing class and global variables.
  • Member functions of a nested class follow regular access rules and have no special access privileges to members of their enclosing classes. Member functions of the enclosing class have no special access to members of a nested class

本地类:
我的这个答案 here 记录了与局部类相关的细微之处。

关于c++ - 本地类、内部类和嵌套类在C++中是一回事吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7878124/

相关文章:

c++ - 如何为全局对象、对象数组以及类/结构中的对象调用构造函数?

c++ - 最低订购要求

java - 静态嵌套接口(interface)的内联实现

c++ - 嵌套局部类的静态方法

c++ - 为嵌套类模板重载运算符<<

java - 为什么我可以访问封闭类引用的私有(private)成员

c++ - 简单的客户端/服务器,TCP/IP 加密消息流,SSL (C++)

c++ - C响应中应在何处使用assert()。 C++?

java - 接口(interface) 拥有内部类会影响接口(interface)的抽象 - OOP

java - 类型不匹配 : cannot convert MyClass<E> to MyClass<E>