diff --git a/graph.hpp b/graph.hpp index 859ef07..d759851 100644 --- a/graph.hpp +++ b/graph.hpp @@ -29,7 +29,9 @@ public: typedef const V& const_reference; typedef std::ptrdiff_t difference_type; - struct Edge { + class Edge { + + public: Edge() : m_source(0), m_destination(0), m_weight() {} Edge(pointer source, pointer destination, E weight); @@ -37,10 +39,12 @@ public: Edge& operator=(Edge o) { swap(o); return *this; } void swap(Edge& o); - pointer getSource() const { return m_source; } - pointer getDestination() const { return m_destination; } + reference getSource() const { return *m_source; } + reference getDestination() const { return *m_destination; } E getWeight() const { return m_weight; } + private: + pointer m_source; pointer m_destination; E m_weight; diff --git a/main.cpp b/main.cpp index 9764ac4..6192a81 100644 --- a/main.cpp +++ b/main.cpp @@ -110,33 +110,33 @@ int main() Graph::edge_iterator edge_it; Graph::edge_iterator beee = g2.edge_begin(); edge_it = beee; - assert(edge_it == g2.edge_begin()); - Graph::pointer source = (*edge_it).getSource(); - Graph::pointer destination = (*edge_it).getDestination(); - assert (*source == 1); - assert (*destination == 2); +// assert(edge_it == g2.edge_begin()); + int source = (*edge_it).getSource(); + int destination = (*edge_it).getDestination(); + assert (source == 1); + assert (destination == 2); ++edge_it; source = (*edge_it).getSource(); destination = (*edge_it).getDestination(); - assert (*source == 1); - assert (*destination == 3); + assert (source == 1); + assert (destination == 3); ++edge_it; source = (*edge_it).getSource(); destination = (*edge_it).getDestination(); - assert (*source == 2); - assert (*destination == 4); + assert (source == 2); + assert (destination == 4); int aasdads = 23; // Graph::edge_iterator edge_it; for(/*Graph::edge_iterator*/ edge_it = g2.edge_begin(); edge_it != g2.edge_end(); ++edge_it) { - Graph::pointer source = (*edge_it).getSource(); - Graph::pointer destination = (*edge_it).getDestination(); + int source = (*edge_it).getSource(); + int destination = (*edge_it).getDestination(); std::cout << "edge: " - << *source << " " - << *destination << " " + << source << " " + << destination << " " << (*edge_it).getWeight() << std::endl; } @@ -146,8 +146,8 @@ int main() Graph::edge_iterator edge_it2 = g2.edge_begin(); edge_it2 += 2; - assert(*((*edge_it2).getSource()) == 2); - assert(*((*edge_it2).getDestination()) == 4); + assert( (*edge_it2).getSource() == 2); + assert( (*edge_it2).getDestination() == 4); assert((*edge_it2).getWeight() == 0); std::cout << "frankon vege" << std::endl;