1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <iostream> #include <string> #include <vector> struct Vertex { public: float x, y, z; Vertex(float x, float y, float z) :x(x), y(y), z(z) {
}
Vertex(const Vertex& vertex) :x(vertex.x), y(vertex.y), z(vertex.z) { std::cout << "Copied!" << std::endl; }
};
std::ostream& operator<<(std::ostream& stream, const Vertex& vertices) { stream << vertices.x << " " << vertices.y << " " << vertices.z; return stream; }
int main() { std::vector<Vertex> vertices; vertices.push_back({ 1,2,3 }); vertices.push_back({ 4,5,6 }); vertices.push_back({ 7,8,9 });
for (int i = 0; i < vertices.size(); i++) std::cout << vertices[i] << std::endl; for (Vertex& v : vertices) std::cout << v << std::endl; vertices.erase(vertices.begin() + 1); for (Vertex& v : vertices) std::cout << v << std::endl; vertices.clear();
std::cin.get(); }
|