vectors[0]为什么我已经pop_back()迈出了第一步仍然可以获得价值?
我猜现在我的vectors已经空了,请致电检查empty()
#include <iostream>
#include <vector>
struct Vector2 {
int x, y;
Vector2(int _x, int _y)
: x(_x)
, y(_y) {}
Vector2(const Vector2& vec)
: x(vec.x)
, y(vec.y) {
std::cout << "[Copy] Vector2{" << x << "," << y << "} copied!"
<< std::endl;
}
void Print() {
std::cout << "[Print] Vector2{" << x << "," << y << "}" << std::endl;
}
};
void PrintVectors(const std::vector<Vector2>& vectors) {
std::cout << "---" << std::endl; …Run Code Online (Sandbox Code Playgroud)