有模板的文件的问题

时间:2019-04-17 17:01:19

标签: c++ templates

为什么我的带有模板功能的单元出现以下情况:

  

C:/Users/Alex/CLionProjects/untitled104/main.cpp:5:对`Queue :: Queue(int)'的未定义引用

     

C:/Users/Alex/CLionProjects/untitled104/main.cpp:6:对“ Queue :: insert_after(int,int)”的未定义引用

     

C:/Users/Alex/CLionProjects/untitled104/main.cpp:7:对`Queue :: insert_after(int,int)'的未定义引用

     

C:/Users/Alex/CLionProjects/untitled104/main.cpp:8:对`Queue :: insert_after(int,int)'的未定义引用

     

C:/Users/Alex/CLionProjects/untitled104/main.cpp:9:对“ Queue :: getSize()”的未定义引用

     

C:/Users/Alex/CLionProjects/untitled104/main.cpp:10:对`Queue :: getNode(int)'的未定义引用

     

C:/Users/Alex/CLionProjects/untitled104/main.cpp:10:对`Node :: getValue()'的未定义引用

请告诉我如何解决。

main.cpp

#include <iostream>
#include "Queue.h"

int main() {
    Queue<int> tmp(2);
    tmp.insert_after(0,0);
    tmp.insert_after(1,1);
    tmp.insert_after(2,9);

    for (int i = 0; i <= tmp.getSize(); ++i) 
        printf("%i",tmp.getNode(i)->getValue());

    return 0;
}

Queue.cpp

#include "Queue.h"

template<typename T>
T Node<T>::getValue() {
    return nullptr;
}

template<typename T>
void Node<T>::setValue(T new_value) {
}

template<typename T>
void Node<T>::deleteNode() {
}

template<typename T>
Node<T> *Node<T>::getNext() {
    return nullptr;
}

template<typename T>
Node<T> *Node<T>::getBack() {
    return nullptr;
}




template<typename T>
Queue<T>::Queue(T value) {
}

template<typename T>
Node<T> *Queue<T>::getFirst() {
    return nullptr;
}

template<typename T>
Node<T> *Queue<T>::getNode(int position) {
    return nullptr;
}

template<typename T>
unsigned int Queue<T>::getSize() {
    return 0;
}

template<typename T>
Node<T> *Queue<T>::insert_after(int position, T value) {
    return nullptr;
}

Queue.h

#ifndef UNTITLED104_QUEUE_H
#define UNTITLED104_QUEUE_H

#include <vector>
#include <cstdio>

using namespace std;


template <typename T>
class Node{
private:
    T value;
public:
    Node *next_node, *back_node;

    Node():next_node(NULL),back_node(NULL){};
    Node(T new_value):value(new_value),next_node(NULL),back_node(NULL){};

    T getValue();
    void setValue(T new_value);
    void deleteNode();
    Node<T>* getNext();
    Node<T>* getBack();
};

template <typename T>
class Queue{
private:
    Node<T>* firstNode=NULL;
    unsigned size=0;
public:
    Queue(T value);
    Node<T>* getFirst();
    Node<T>* getNode(int position);
    unsigned int getSize();
    Node<T>* insert_after(int position, T value);
};

#endif //UNTITLED104_QUEUE_H

0 个答案:

没有答案
相关问题