Reputation: 9405
I've been struggling with a linker error that i cant seem to figure out, I'm implementing the bellman ford algorithm as a part of my homework.
Here's the code i've written so far, it'd be great if someone could explain why i'm getting that error, I've pasted my code on mozilla pastebin, the two files are graph.h : http://pastebin.mozilla.org/1193147 and bellman_ford.cpp : http://pastebin.mozilla.org/1193148
All solutions will be most appreciated and thanks to people for taking out their valuable time to help me out.
Upvotes: 1
Views: 132
Reputation: 93468
You forgot to implement the constructor of Vertex.
class Vertex
{
private:
char vertex_name;
public:
Vertex() { };
Vertex(char n)
{
vertex_name = n;
}
//Method signatures
char get_name();
};
Upvotes: 0
Reputation: 91320
You didn't implement Vertex::Vertex()
or Edge::Edge()
- they're only declared.
Implement them like this:
class Vertex
{
private:
char vertex_name;
public:
Vertex() {}
...
class Edge
{
private:
Vertex source,destination;
int weight;
public:
Edge() {}
...
You'll also get errors if you include graph.h
from more than one cpp file. You should move the bodies of your member functions into a graph.cpp
file instead of implementing them in the header the way you do.
Upvotes: 3