成员类型是如何实现的
How are member types implemented?
我正在看这个资源:
http://www.cplusplus.com/reference/vector/vector/例如,vector类上的迭代器成员类型。
"成员类型"是否可以在vector类中简单地实现为类型定义或类似的东西?我不清楚"成员类型"到底是什么意思,我看过几本c++教科书,它们甚至根本没有提到这个短语。
c++标准也没有使用这个短语。相反,它会将其称为嵌套类型名称(第9.9节)。
有四种方法可以得到一个:
class C
{
public:
typedef int int_type; // as a nested typedef-name
using float_type = float; // C++11: typedef-name declared using 'using'
class inner_type { /*...*/ }; // as a nested class or struct
enum enum_type { one, two, three }; // nested enum (or 'enum class' in C++11)
};
嵌套类型名称在类范围内定义,为了从该范围外引用它们,需要名称限定:
int_type a1; // error, 'int_type' not known
C::int_type a2; // OK
C::enum_type a3 = C::one; // OK
Member type简单地表示(该类的)成员类型。它可以是您所说的typedef
(在vector
的情况下,它可能是T*
),也可以是嵌套的class
(或struct
)。
成员类型可以指'嵌套类'或'嵌套结构'。它意味着类中的类。如果您想参考教科书,那么搜索"嵌套类"。
相关文章:
- 如果没有malloc,链表实现将失败
- 如何在c++中实现处理器调度模拟器
- 如何在c++中使用引用实现类似python的行为
- 实现无开销push_back的最佳方法是什么
- 使用简单类型列表实现的指数编译时间.为什么
- 如何在BST的这个简单递归实现中消除警告
- 实现一个在集合上迭代的模板函数
- 我应该实现右值推送功能吗?我应该使用std::move吗
- 如何正确实现和访问运算符的各种自定义枚举器
- C++Union/Struct位域的实现和可移植性
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 在c++中实现LinkedList时,应出现未处理的错误
- 为左值和右值的包装器实现C++范围
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- 使用GSoap实现ONVIF
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 用于AVX的ln(x)的实现,m256
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 如何实现内部实现依赖于模板参数的类
- 我的 PRNG 实现与我尝试复制的实现有何不同?