向量::size_type c++

时间:2022-02-26 16:38:43

What is meant by this C++ statement?

这个c++语句是什么意思?

vector<int>::size_type x;

And, what is the use of the scope operator :: here? In other words, how do we read this statement in English?

那么,scope运算符的用法是什么呢:here?换句话说,我们如何用英语读这句话?

For example, for X::x(){...}, we say that x() is a member function of class X.

例如,对于X::X(){…},我们说x()是类x的一个成员函数。

3 个解决方案

#1


55  

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.

size_type是类型向量 的(静态)成员类型。通常,它是std: size_t的类型定义,它本身通常是无符号int或无符号long的类型定义。

#2


21  

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.

我将它解读为“将x声明为适合保持向量大小的类型的变量”。向量为它的长度定义了自己的类型,如果可能的话,使用它总是最干净的,而不是“猜测”,直接使用int、unsigned int、long、unsigned long或size_t等等,因为您需要这样做。

#3


3  

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.

因此,带有int的向量类型有一个名为size_type的成员类型。x被定义为该类型的变量。

#1


55  

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.

size_type是类型向量 的(静态)成员类型。通常,它是std: size_t的类型定义,它本身通常是无符号int或无符号long的类型定义。

#2


21  

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.

我将它解读为“将x声明为适合保持向量大小的类型的变量”。向量为它的长度定义了自己的类型,如果可能的话,使用它总是最干净的,而不是“猜测”,直接使用int、unsigned int、long、unsigned long或size_t等等,因为您需要这样做。

#3


3  

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.

因此,带有int的向量类型有一个名为size_type的成员类型。x被定义为该类型的变量。