vector::size_type in C++

后端 未结 3 442
自闭症患者
自闭症患者 2020-11-27 03:27

What is meant by this C++ statement?

vector::size_type x;

And, what is the use of the scope operator :: here? In ot

相关标签:
3条回答
  • 2020-11-27 03:37

    size_type is a (static) member type of the type vector<int>. Usually, it is a typedef for std::size_t, which itself is usually a typedef for unsigned int or unsigned long long.

    0 讨论(0)
  • 2020-11-27 03:47

    I would read it as "declare x as a variable of a type suitable for holding the size of a vector". The vector defines its own type for its length, and it's always cleanest to use that if possible, rather than "guessing" and using int, unsigned int, long, unsigned long or size_t etc directly as you'd otherwise need to do.

    0 讨论(0)
  • 2020-11-27 03:48

    vector is a template

    so the vector type templated with int has a member typedef called size_type. x is defined as a variable of that type.

    0 讨论(0)
提交回复
热议问题