Vector class in C ++ programming

Can someone explain to me what the use of a vector class is? My professor mentioned the following sentence in a lecture. Pattern: each vector has a class parameter that determines what type of object this instance will use, commonly called T. I don’t understand what the class parameters mean exactly?

+3
source share
4 answers

A vector is defined as a pattern, for example:

template<typename T>
class Vector;

To use it, you need to create an instance of the template, for example:

Vector<char> myVector;

. , , T ( char)

,

template<typename T>
class DataHolder{ 
public:
 T data
}

:

DataHolder<char> myChar;

:

class DataHolder
{
public:
 char data;
}
+2

vector ++ . vector.

int arr[];  // Static C++ array with int elements
vector<int> v; // dynamic array with int elements

int - .

, " " . " ".

+13

:

std::vector<int> v;

vector ( ) int. .

There are many resources on the Internet about basic C ++. See, for example, this page for more information on STL vectors.

+1
source

Source: https://habr.com/ru/post/1765166/


All Articles