Note how we set up the overloaded input and output operators as usual with the class methods grab and print. This will allow us to trasparently print out the contents of arbitrary edge and node later when we allow such data to be typeless.
#include <string.h>
#include <iostream.h>
#include "edge.h"
istream& operator>>(istream& in, Edge& A)
{A.grab(in); return(in);}
istream& operator>>(istream& in, Edge* A)
{A->grab(in); return(in);}
ostream& operator<<(ostream& out,const Edge& A)
{A.print(out); return(out);}
ostream& operator<<(ostream& out,const Edge* A)
{A->print(out); return(out);}
istream& Edge::grab(istream& input)
{
cout << "Please enter the edge weight:" << endl;
input >> d_weight;
return input;
}
ostream& Edge::print(ostream& output) const
{
output << d_weight << endl;
return output;
}
Edge::Edge(){d_weight = 0.0;}
Edge::Edge(double weight)
{
d_weight = weight;
}
Edge::Edge(const Edge& T)
{
d_weight = T.d_weight;
}
Edge::~Edge()
{
//stub
}
Edge& Edge::operator=(const Edge& T)
{
if(&T!=this){
d_weight = T.d_weight;
return *this;
}
else
return *this;
}
double Edge::weight() const
{
return d_weight;
}