I am trying to use (learn) the Vectors in C++ and hence I have written this as a simple example. But I getting the error of 'Segmentation fault: core dumped' and I do not where and what the error is. Can someone try to explain me , what it is?
'''
struct Vertex {
int x,y,z;
};
std::ostream& operator<<(std::ostream& stream, const Vertex& vertex) {
stream << vertex.x << ", " << vertex.y << vertex.z;
return stream;
}
int main() {
std::vector<Vertex> vertices;
vertices.push_back({1,2,3});
for(int idx = 0; vertices.size(); idx++)
std::cout << vertices[idx] << std::endl;
}
'''
Is ther error because of the operator overloading (<<)? This is just a hunch. Because, When i compile it using g++11, it compiles fine, but when I see the output (using the command ./a.out), the segmentation fault error occurs. Therefore, I am confused.