Vector and types of vector constructors and vector operators in C++

A vector is a dynamic array and its size doesn’t needs to be declared before compile time. It can dynamically adjust its size. Vectors are powerful and flexible but are less efficient than regular arrays.

A vector class can be declared as:

template <class T, class Allocator = allocator<T>> class vector

An object that has to be stored in vector has to define a default construcutor.

Types of vector constructors:

Type-1: Empty vector

explicit vector(const Allocator &a = Allocator( ) );

Type-2: Vector having x elements and y values

explicit vector(size_type x, const T &y = T ( ), const Allocator &a = Allocator( ));

Type-3: Vector having same elements as obj

vector(const vector<T, Allocator> &obj); template <class InIter> vector(InIter start, InIter end,

Type-4: Vector having iterators i and j

template <class InIter> vector(InIter i, InIter j, const Allocator &a = Allocator( ));

Types of vector operators: [ ], ==, <, <=, !=, >, >=

Leave a Reply