我试图理解为什么我可以在以下代码中使用 ostream_iterator forEdge1但不能使用 for Edge:
#include <fstream>
#include <iostream> // for std::cout
#include <utility> // for std::pair
using VertexName = uint32_t;
using Edge = std::pair<VertexName, VertexName>;
struct Edge1 : public Edge {
Edge1(VertexName x, VertexName y) : Edge(x,y) {};
};
std::ostream&
operator<<(std::ostream& os, const Edge& e) {
os << "(" << e.first << ", " << e.second << ")";
return os;
}
int main(int,char*[])
{
auto e1 = Edge(4,5);
auto e2 = Edge1(5,6);
std::cout << e1 << …Run Code Online (Sandbox Code Playgroud)