gpt4 book ai didi

c++ - 成员类型是如何实现的?

转载 作者:IT老高 更新时间:2023-10-28 22:33:09 26 4
gpt4 key购买 nike

我在看这个资源:

http://www.cplusplus.com/reference/vector/vector/

例如,类 vector 上的迭代器成员类型

“成员类型”是否可以简单地实现为 typedef 或 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

关于c++ - 成员类型是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14037392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com