There is another solution to your particular problem.
Your Edge class isn't using the constructor list to intialize its members, as it should do.
As you don't use the constructor list the two Vertex member variables (the two vertices -- vStart and vEnd) are being initialized by their default constructor (when you provide one, as Duoas suggested) and then assigned to in the constructor body to the values of the passed in parameters.
If you switch to using the constructor initializer list like this:
1 2 3 4 5 6 7 8 9 10
|
Edge::Edge(Vertex& vStart, Vertex& vEnd, int eWeight)
: start(vStart), end(vEnd), weight(eWeight) // init members in constructor init list
{
// don't assign here
//start=vStart;
//end=vEnd;
//weight=eWeight;
vStart.add_adjacent(vEnd);
vEnd.add_adjacent(vStart);
}
|
then it's the Vertex(const Vertex&); form off the constructor that's used instead. In this case you can do without a default constructor for your Vertex class, at least in the code you've posted above.
I don't know the details of the rest of your program, but it is a good idea in general to provide default constructors. But there are situations where a particular class is invalid without some kind of initialization information, and the initializer list is part of how you deal with that case.
Andy
PS A pet peeve of mine!
I would rather see
Edge(Vertex& vStart, Vertex& vEnd, int eWeight);
than
Edge(Vertex&, Vertex&, int);
in your header edge.h
You see, I get narked when digging through codebases (not always using a smart IDE) where I have to grovel round to find out what a parameter means. The header to a class should make it absolutely clear what the parameters are, without having to go and find the .cpp file (which might not even be about if I've been given a header and a .LIB file.)