Linux中未定义的引用错误

时间:2016-09-21 03:48:10

标签: c++ linux referenceerror

嘿,我把一些程序转移到Linux服务器上,现在我收到一个“未定义的引用”错误,并且想知道你们是否可以帮助我。

我的主要是

#include <iostream>
#include "Stack.h"
using namespace std;

int main() {
        Stack istk;
        istk.push(3.4);
        istk.push(4.5);
        istk.pop();
        istk.push(7.1);
        cout << istk.top() << endl;
        istk.pop();
        istk.pop();
        cout << istk.top() << endl;
   return 0;
}

这是Stack.h

#ifndef STACK_H
#define STACK_H
#include "Node.h"

class Stack
{
private:
        Node* tos;


public:
        Stack();
        ~Stack();
        int is_empty() const;
        int is_full() const;
        void push(double);
        void pop();
        double top() const;

};

#endif

这是Stack.cpp

#include <iostream>
#include <cassert>

Stack::Stack():tos(NULL) {
}


int Stack::Stack is_empty() const {
        return tos == NULL;
}

int Stack::Stack is_full() const {
        return 0;
}

void Stack::Stack push(double d) {
        Node* newNode = new Node(d);
        if (is_empty()) {
                tos = newNode;
        }
        else {
                newNode->next = tos;
                tos = newNode;
        }

}

double Stack::Stack top() const{
        assert(!is_empty());
        return tos->data;
}

void Stack::Stack pop() {
        assert(!is_empty());
        Node* discard = tos;
        tos = tos->next;
        delete discard;


}
Stack::~Stack()
{
        while (!is_empty()) {
                pop();
        }
}

我得到的错误都与Stack函数的引用错误有关。

0 个答案:

没有答案