c++ - LNK 2019/1120 Errors with my header/source file practice with 双链表

标签 c++ header lnk2019

你能帮我弄清楚为什么我会收到这些 2019 错误吗?我很确定所有文件都保存在正确的位置,而且我认为我对头文件使用了正确的约定?这是我的系统编程类(class)的实验室。

错误如下:

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall DLL::intDLL::intDLL(void)" (??0intDLL@DLL@@QAE@XZ) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall DLL::intDLL::~intDLL(void)" (??1intDLL@DLL@@QAE@XZ) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall DLL::intDLL::addFront(int)" (?addFront@intDLL@DLL@@QAEXH@Z) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall DLL::intDLL::getFront(void)" (?getFront@intDLL@DLL@@QAEHXZ) referenced in function _main

1>c:\users\josh\documents\visual studio 2012\Projects\Lab10\Debug\Lab10.exe : fatal error LNK1120: 4 unresolved externals

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

最佳答案

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

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链接。

关于c++ - LNK 2019/1120 Errors with my header/source file practice with 双链表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14844411/

相关文章:

c++ - clang 静态分析器(扫描构建)可以与 cmake --build 一起使用吗?

c++ - 在 native c++ 应用程序中注册 Windows 运行时组件 (c++winrt)

Android ListActivity - 固定页眉和页脚

c++ - 如何在反向抛光计算器中添加多位整数

c++ - 在元组中搜索函数的参数

html - 如何移动页眉的标题使其与页面的主要内容对齐?

c++ - 添加包含导致编译错误

c++ - 将静态库链接到 Visual C++ 中的新项目

c++ - 使用 C++ 在 directX 11 中的 VS 2013 中获取 LNK 2019 错误

C++ LNK2019 未解析的外部符号