C++ 什么是点的向量?

C++ 什么是点的向量?,c++,vector,point,C++,Vector,Point,考虑以下定义: vector < vector < Point > > convexHulls(contours.size()); vectorconvexHulls(contours.size()); 我知道vector能够在插入或删除元素时自动调整自身大小 但我不明白这个向量能存储什么 为什么有两个向量vector点< /Cord>”的类型。从上下文中,我们可以猜测它是一个用户定义的类。它必须是在程序中的其他地方定义的。@eerorika vector等高线;这用

考虑以下定义:

vector < vector < Point > > convexHulls(contours.size());
vector>convexHulls(contours.size());
我知道vector能够在插入或删除元素时自动调整自身大小

但我不明白这个向量能存储什么


为什么有两个向量
vector
以及什么是
Point

vector是一个模板类,它可以存储您在定义它时要求它存储的任何内容。例如:

vector<int>      // vector that will store any number of integers
vector<double>   // vector of double precision floating points
vector<string>   // vector of strings
vector<T>        // vector of Ts, being understood that T is a type

这应该是有用的:向量可以存储任何其他类型的对象。指定向量时,需要告诉向量它存储的对象类型。例如,
int
s的
vector
不同于
double
s的
vector
。在这种情况下,此函数
convexHulls
,返回
点的
向量的
向量。包含的库应该指定点是什么。例如,
向量可以存储
int
s。一般情况下,
vector
存储
T
s<代码>矢量
因此存储
点的矢量。它是一个二维向量(但每个子向量可以具有不同的长度)。C++中没有一个名为“代码>点< /Cord>”的类型。从上下文中,我们可以猜测它是一个用户定义的类。它必须是在程序中的其他地方定义的。@eerorika vector>等高线;这用于定义向量<向量<点>>等高线@好的。而
convxhulls
是使用与
等高线
相同数量的项目(在本例中为行)创建的。但是每一行都是由0个元素组成的向量,这些元素要么被调整大小,要么被推回()。
vector<vector<int>>    // vector of vectors, aka 2D vector of integers
vector<vector<Point>>  // 2D vector of Points, where Points is a type, probably a class
vector<vector<int>> m { { 1,  2,  3,  4}, 
                        { 5,  6,  7,  8},
                        { 9, 10, 11, 12} };
cout << m[1][2]<<endl;  // line 1, item 2 (numbering start with 0) -> 7                        
struct Point { int x, y; };