2012-12-26 63 views

回答

24

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 
+3

我希望本网站的每一个答案都能提供清晰,简单和高效。谢谢。 – johnbakers

1

成员类型仅代表(该类的成员)类型。如您所说,它可能是typedef(在vector的情况下,它很可能是T*),也可能是嵌套class(或struct)。

1

成员类型可能指'嵌套类'或'嵌套结构'。 它意味着另一类中的类。如果你想参考教科书,然后搜索“嵌套类”。

相关问题