Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vector<int>::size_type in C++

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.

like image 705
Simplicity Avatar asked Jan 31 '11 10:01

Simplicity


People also ask

What is size_type?

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 .

What does Vector member size () do?

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.

What is Size_t and size_type?

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.

Does vector size return an int?

This is because vector. size() returns a size_t type value, which is an alias for unsigned long int .


1 Answers

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.

like image 155
fredoverflow Avatar answered Sep 21 '22 04:09

fredoverflow