简体   繁体   中英

Help with C++ linker error

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.

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.

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();  
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM