如何修复“未解决的外部符号公共:thiscall错误?”

时间:2019-05-25 04:46:51

标签: c++

我遇到了两个错误 1.“函数_main中引用的未解析的外部符号“ public:__thiscall Stack :: Stack(void)”(?? 0?$ Stack @ D @@ QAE @ XZ)) 2.在函数_main中引用的“未解析的外部符号“ public:虚拟__thiscall Stack ::〜Stack(void)”(?? 1?$ Stack @ D @@ UAE @ XZ)”

此错误是什么以及如何解决?

Stackinterface.h

#pragma once
#ifndef STACKINTERFACE_H
#define STACKINTERFACE_H

using namespace std;

template <typename T>
class StackInterface {
public:
    StackInterface() {};
    virtual ~StackInterface() {};
    virtual bool isEmpty() const = 0;
    virtual bool isFull() const = 0;
    virtual void push(T&data) = 0;
    virtual void pop() = 0;
    virtual T top() const = 0;
};
#endif

Stack.h

#pragma once
#ifndef STACK_H
#define STACK_H
#include "StackInterface.h"

#include <iostream>
template <typename T>
class Stack : public StackInterface<T> {
private:
    T * items;
    const static int max = 10;
    const static int GROWBY = 5;
    size_t arrayCapacity;
    size_t numItems;
    int top_position;
public:
    Stack();
    ~Stack();
    virtual void push(T&data);
    virtual T top() const;
    virtual void pop();
    virtual bool isEmpty() const;
    virtual bool isFull() const;
    size_t getArrayCapacity();
    size_t getNumItems();
};
#endif

Stack.cpp

#include "Stack.h"

template <typename T>
Stack<T>::Stack()
{
    arrayCapacity = max;
    items = new T[max];
    numItems = 0;
    top_position = -1;
}

template <typename T>
Stack<T>::~Stack() {
    delete[] items;
}

template <typename T>
void Stack<T>::push(T&data) {
    cout << "inserting" << data << endl;
        top_position++;
        items[top_position] = data;
}
template <typename T>
void Stack<T>::pop() {
    if (isEmpty) {
        cout << "The stack is empty. Returned value not reliable.\n";
    }
    else {
        cout << "removing" << top() << endl;
        top_position--;
        return items[top_position];
    }
}

template <typename T>
bool Stack<T>::isEmpty() const
{
    if (numItems == 0) {
        return true;
    }
    else {
        return false;
    }
}

template <typename T>
bool Stack<T>::isFull() const
{
    if (numItems == max) {
        return true;
    }
    else {
        return false;
    }
}

template <typename T>
T Stack<T>::top() const
{
    if (!isEmpty()) {
        return T[top_position];
    }
    else {
        throw exception;
    }
}

template <typename T>
size_t Stack<T>::getArrayCapacity() {
    return arrayCapacity;
}

template <typename T>
size_t Stack<T>::getNumItems() {
    return numItems;
}

主要

#include "Stack.h"


int main() {
    Stack<char> S1;

    return 0;
}

0 个答案:

没有答案