2

This question arises from question related to c++ regex I just asked.

In online cpp references e.g. match_results, what does value_type in "Member types" section means? Is this some standard way of defining classes? How to read this whole "Member Types" section?

JamesWebbTelescopeAlien
  • 3,547
  • 2
  • 30
  • 51

1 Answers1

2

Member types are just typedefs (or sometimes full classes) that are useful for using and/or somehow related to the class itself.

As you ask about member types in general, lets take std::vector as example:

template < class T, class Alloc = allocator<T> > class vector;  

It's a template with type T (and an allocator, doesn't matter).

Now, std::vector contains an member type std::vector::value_type, which always is defined to be the same type as T. Eg for vector<int>, std::vector::value_type is the same as int, and you can use it to define new variables etc.
Similar, there are pointer and reference and some other things which resolve to int* and int&.

Then, there is size_type, which defines a variable suitable to hold all possible vector length values ... Because eg. it's usually different on X86 and X64 (and, for some classes, it can depend on the implementation, and...), it's useful to have somthing like that.

And so on...

deviantfan
  • 11,268
  • 3
  • 32
  • 49