When I push_back()
3 items into a vector
, the copy constructor is triggered 6 times. I can't understand the logic behind this, can you help?
struct vertex{
float x, y, z;
vertex(float x, float y, float z) : x(x), y(y), z(z){
}
vertex(const vertex& other) : x(other.x), y(other.y), z(other.z){
std::cout << "copied" << std::endl;
}
};
int main(){
std::vector<vertex> vertices;
vertices.push_back(vertex(1, 2, 3));
vertices.push_back(vertex(4, 5, 6));
vertices.push_back(vertex(7, 8, 9));
}