#include#include int main() { Vector3 v(1, 2, 3); float x = v.getX(); std::cout << "X Component: " << x << std::endl; return 0; }
X Component: 1
#include#include int main() { std::vector vectors; vectors.push_back(Vector3(1, 2, 3)); vectors.push_back(Vector3(4, 5, 6)); vectors.push_back(Vector3(7, 8, 9)); for (auto v : vectors) { float x = v.getX(); std::cout << "X Component: " << x << std::endl; } return 0; }
X Component: 1 X Component: 4 X Component: 7In this example, we create a vector of Vector3 objects and push three Vector3 objects with values (1, 2, 3), (4, 5, 6) and (7, 8, 9) into it. Then, we iterate through the vector and output the X component of each Vector3 object. The output shows the values of the X component for each object. Package/Library: This code example may use the standard vector library in C++.