What is meant by this C++ statement?
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?
For example, for X::x(){...}
, we say that x()
is a member function
of class X
.
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() – Returns the number of elements in the vector. max_size() – Returns the maximum number of elements that the vector can hold. capacity() – Returns the size of the storage space currently allocated to the vector expressed as number of elements.
size_t is defined as the type used for the size of an object and is platform dependent. container::size_type is the type that is used for the number of elements in the container and is container dependent.
This is because vector. size() returns a size_t type value, which is an alias for unsigned long int .
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With