【问题标题】:LNK 2019 / 1120 Errors with my header / source file practice with Double Linked ListsLNK 2019 / 1120 错误与我的头文件/源文件实践与双链表
【发布时间】:2013-01-28 11:01:44
【问题描述】:

您能帮我弄清楚为什么会出现这些 2019 年错误吗?我很确定所有文件都保存在正确的位置,并且我认为我对头文件使用了正确的约定?这是我的系统编程课的实验室。

以下是错误:

1>main.obj:错误 LNK2019:未解析的外部符号“公共: __thiscall DLL::intDLL::intDLL(void)" (??0intDLL@DLL@@QAE@XZ) 在函数_main中引用

1>main.obj:错误 LNK2019:未解析的外部符号“公共: __thiscall DLL::intDLL::~intDLL(void)" (??1intDLL@DLL@@QAE@XZ) 在函数_main中引用

1>main.obj : 错误 LNK2019: 无法解析的外部符号“public: void __thiscall DLL::intDLL::addFront(int)" (?addFront@intDLL@DLL@@QAEXH@Z) 在函数 _main 中引用

1>main.obj:错误 LNK2019:未解析的外部符号“public:int __thiscall DLL::intDLL::getFront(void)" (?getFront@intDLL@DLL@@QAEHXZ) 在函数 _main 中引用

1>c:\users\josh\documents\visual studio 2012\Projects\Lab10\Debug\Lab10.exe:致命错误 LNK1120:4 未解决的外部问题

intDLL.h 文件:

#include <iostream>
using std::cout;
using std::endl;

class intDLL {

public:
    intDLL();
    intDLL(const intDLL &original);
    ~intDLL();
    void addFront(int inValue);
    void addBack(int inValue);
    void setBack();
    int getFront();
    int getBack();

    struct node {
        int value;
        node *next;
        node *prev;
    };

private:
    node *front;
    node *back;

};

intDLL.cpp

#include <iostream>
#include "intDLL.h"
using std::cout;
using std::endl;


intDLL::intDLL() {
    front = 0;
    back = 0;
}

void intDLL::setBack() {
    node *tempNode = new node;
    if(front == 0) {
        return;
    }

    tempNode = front;
    while(tempNode->back != 0) {
        tempNode = tempNode->prev;  
    }

    back = tempNode;
}

void intDLL::addFront(int inValue) {
    if(front == 0) {
        node *newFront = new node;
        newFront->value = inValue;
        newFront->next = 0;
        newFront->prev = 0;
    }
    else {
        node *newFront = new node;
        newFront->value = inValue;
        newFront->prev = front;
        front->next = newFront;
        newFront->next = 0;
        front = newFront;
    }

    setBack();
}

void intDLL::addBack(int inValue) {
    setBack();
    node *newBack = new node;
    newBack -> value = inValue;
    back->prev = newBack;
    newBack->next = back;
    back = newBack;
}

int intDLL::getFront() {
    return front->value;
}

int intDLL::getBack() {
    return back->value;
}

主要:

#include <iostream>
#include "intDLL.h"
using std::cout;
using std::endl;

int main(int argc, char* argv[]) {
    intDLL test = intDLL();
    test.addFront(3);
    test.addFront(4);
    test.addFront(5);
    std::cout << test.getFront() << endl;

    return 0;
}

【问题讨论】:

  • 请显示完整的错误信息。我从LNK2019 得到的唯一提示是它必须与链接器相关。
  • 添加了错误信息。为什么在我的第一个帖子上投反对票? :(
  • 因为只输出原始代码并说“我有错误消息”并不好。删除了反对票。但是您仍然应该添加详细信息,例如如何编译它

标签: c++ header lnk2019


【解决方案1】:

不确定真正的错误消息是什么,但您似乎还没有实现一些功能,例如

intDLL(const intDLL &original);
~intDLL();

检查您的函数定义以确保声明的每个函数都已定义。还要确保所有 cpp 文件都已编译和链接。

另一个错误是intDLL::node has no back member

void intDLL::setBack() {
    intDLL::node *tempNode = new node;
     ^^^^ node is defined in intDLL, you need provide scope
    if(front == 0) {
       return;
    }

  tempNode = front;
  while(tempNode->back != 0) {
                  ^^^ intDLL::node has no back member
    tempNode = tempNode->prev;  
   }

  back = tempNode;
}

查看此SO 链接。

【讨论】:

  • 我注释掉了在头文件中声明的那些未使用的函数(由于这些错误还没有编写它们),并得到了相同的最后 3 条错误消息。我假设当我在 Visual Studio 2012 中“不调试就开始”时,它编译了项目中的所有文件并进行了适当的链接。不是这样吗?
猜你喜欢
  • 2014-09-15
  • 2014-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
  • 1970-01-01
相关资源
最近更新 更多