简体   繁体   English

帮助C ++链接器错误

[英]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. 我一直在努力解决似乎无法弄清楚的链接器错误,我正在将bellman ford算法作为作业的一部分。

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 这是我到目前为止编写的代码,如果有人可以解释为什么我会得到这个错误,那真是太好了,我已经将代码粘贴到了mozilla pastebin上,这两个文件是graph.h: http:// pastebin .mozilla.org / 1193147和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. 您没有实现Vertex::Vertex()Edge::Edge() -它们只是声明。

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. 如果您从多个cpp文件中包含graph.h ,也会收到错误graph.h 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. 您应该将成员函数的主体移到graph.cpp文件中,而不是像在标头中那样实现它们。

You forgot to implement the constructor of Vertex. 您忘记了实现Vertex的构造函数。

class Vertex
{
  private:
    char vertex_name;
  public:
    Vertex() { };

    Vertex(char n)
    {
      vertex_name = n;
    }
//Method signatures
    char get_name();  
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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