vector<Point<T>*> vertices;什么意思
时间: 2023-12-07 16:02:27 浏览: 118
point-in-polygon:使用 Sweep Line 方法确定点是否在多边形内
这段代码定义了一个名为 `vertices` 的变量,它是一个指向 `Point<T>` 类型指针的向量(vector)。`Point<T>` 是一个泛型类,`T` 是一个占位符,表示可以是任何;
cout << " XX" << endl;
cout << " XX" << endl;
cout << " XX" << endl;
cout << " XX" << endl;
cout << " XX" << endl;
cout << " XX" << endl;
cout << " XX" << endl;
cout << " XX" << endl;
cout << " XXXX" << endl;
cout << " XXXXXX" << endl;
cout << " XXXXXXXX" << endl;
cout << " XXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXXXXXXXXXX" << endl;
cout << " XXXXXXXXXXXX" << endl;
cout << " XXXX" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout类型。这个向量中存储的是 `Point<T>` 类型的指针,而不是实际的对象。 << " X" << endl;
cout << " X" << endl;
cout << " X这意味着这个向量存储的是 `Point<T>` 对象的地址,而不是对象本身。在" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " X" << endl;
cout << " 使用时,需要先将对象动态分配内存,然后将其地址存储在 `vertices` 向量中。 X" << endl;
cout << " X" << endl;
cout << " X" << endl;
例如,可以使用类似下面的代码向 `vertices` 中添加一个 `Point<T>` 对象的指针:
```
cout << " X" << endl;
cout << " X" << endl;
cout << " Point<T>* p = new Point<T>(x, y);
vertices.push_back(p);
```
注意,使用完毕后需要手动 X" << endl;
cout << " X" << endl;
cout << " X" << endl释放内存,以避免内存泄漏:
```
for (int i = 0; i < vertices.size(); i;
cout << " X" << endl;
cout << " X" << endl;
cout << "++) {
delete vertices[i];
}
```
这段代码会释放 `vertices` 向量中所有元素所指向的内存。
阅读全文