johnbakers
johnbakers

Reputation: 24760

How are member types implemented?

I'm looking at this resource:

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

For example, the iterator member type on class vector.

Would a "member type" simply be implemented as a typedef or something similar in the vector class? It is not clear to me what "member type" actually means, and I've looked at a couple C++ textbooks, they don't even mention this phrase at all.

Upvotes: 27

Views: 10038

Answers (3)

jogojapan
jogojapan

Reputation: 69977

The C++ Standard does not use this phrase either. Instead, it would call it a nested type name (§9.9).

There are four ways to get one:

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)
};

Nested type names are defined in class scope, and in order to refer to them from outside that scope, name qualification is required:

int_type     a1;          // error, 'int_type' not known
C::int_type  a2;          // OK
C::enum_type a3 = C::one; // OK

Upvotes: 46

Mian Zeshan Farooqi
Mian Zeshan Farooqi

Reputation: 311

Member type may refer to 'nested class' or 'nested structure'. It means class inside another class. If you want to refer text books then search for 'nested classes'.

Upvotes: 2

Karthik T
Karthik T

Reputation: 31952

Member type simply stands for a type that is a member(of that class). It could be a typedef as you say (in the case of vectorit is likely to be T*) or it could be nested class (or struct).

Upvotes: 4

Related Questions