首页 文章

LNK 2019/1120错误我的 Headers /源文件使用双链表进行练习

提问于
浏览
2

你能帮我搞清楚为什么我会得到这些2019年的错误吗?我很确定所有文件都保存在正确的位置,我想我正在使用头文件的正确约定?这是我的系统编程类的实验室 .

以下是错误:

1> main.obj:错误LNK2019:未解析的外部符号“public:__thiscall DLL :: intDLL :: intDLL(void)”(?? 0intDLL @ DLL @@ QAE @ XZ)在函数_main 1> main.obj中引用:错误LNK2019:未解析的外部符号“public:__thiscall DLL :: intDLL :: ~intDLL(void)”(?? 1intDLL @ DLL @@ QAE @ XZ)在函数_main 1> main.obj中引用:错误LNK2019:未解析的外部符号函数_main 1> main.obj中引用的“public:void __thiscall DLL :: intDLL :: addFront(int)”(?addFront @ intDLL @ DLL @@ QAEXH @ Z):错误LNK2019:未解析的外部符号“public:int __thiscall函数_main 1> c:\ users \ josh \ documents \ visual studio 2012 \ Projects \ Lab10 \ Debug \ Lab10.exe中引用的DLL :: intDLL :: getFront(void)“(?getFront @ intDLL @ DLL @@ QAEHXZ) :致命错误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;
}

1 回答

  • 0

    不确定什么是真正的错误消息,但似乎你没有实现一些函数,为样本

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

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

    另一个错误是 intDLL::node 没有后退成员

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

相关问题