c++ - 我的程序未发现struct中的功能

我的程序没有发现在结构节点中创建的函数returnTest或其他新函数。 g++编译器返回此错误:

linkedList.cpp: In instantiation of 'void LinkedList<T>::insert(T) [with T = int]':
linkedList.cpp:37:22:   required from here
linkedList.cpp:31:13: error: 'struct LinkedList<int>::Node' has no member named
'returnTest' std::cout << auxHead->returnTest();

我的文件是:

Main.cpp

#include "linkedList.hpp"
#include <iostream>
#include <cstdlib>

template<class T> LinkedList<T>::LinkedList()
{
    node = NULL;
}

template<class T> LinkedList<T>::~LinkedList()
{
}

template<class T> bool LinkedList<T>::isEmpty(){

}

template<class T> int LinkedList<T>::size(){
    if (node == NULL)
        return 0;
}

template<class T> void LinkedList<T>::insert(T element){
    Node *auxHead = node;

    if (auxHead == NULL){
        Node* newNode = new Node();
        newNode->data = element;
        node = newNode;
    }else{
        std::cout << auxHead->returnTest();
    }
}

int main(){
    LinkedList<int> *newLinked = new LinkedList<int>();
    newLinked->insert(55);
    newLinked->insert(55);
    return 0;
}

LinkedList.hpp

#ifndef __LINKEDLIST_H_
#define __LINKEDLIST_H_

#include <stdio.h> 

template <class T> class LinkedList {
    private:
        struct Node {
            T data = NULL;
            Node *next;

            T getData(){
                return data;
            }

            Node getNext(){
                return next;
            }

            int returnTest(){
                return -1;
            }

            T isNIL(){
                return (data == NULL);
            }
        };
        Node *node = NULL;
    public:
        LinkedList();
        ~LinkedList();
        bool isEmpty();
        int size();
        void insert (T&);
};

#endif

我的g++版本是4.8.1。请忽略方法size()

最佳答案

无法用于模板类/功能的实现。只需将实现(位于.cpp中)放入头文件中即可。

https://stackoverflow.com/questions/23025221/

相关文章:

c++ - '' *2之前的解析错误

c# - 如何正确地将 Dictionary,Object

.net - 使用xmlrpc和vb.net在wordpress中发布错误

c# - C#中的编译时错误

c++ - 代码编译错误

php - PHP中 undefined index 错误

c++ - header 多重重新定义

python - 使用 MinGW+GCC 编译 SciPy 时编译器失败

c++ - 在此范围C++中未声明错误 'menu'

android - Android代码抛出错误