我的程序没有发现结构中的函数
My program not discovery the functions in struct
我的程序没有发现在structNode中创建的函数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();
我的文件是:
主要.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;
}
链接列表.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中)放入头文件即可。
相关文章:
- 使用不带参数的函数访问结构元素
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 链表,反向函数,数据结构
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 需要帮助将结构数组传递给函数
- 使用cpp中的结构和函数的多个学生条目
- 如何传递带有通过引用传递的结构参数的函数?
- 在类构造函数中使用结构变量
- 在 c++ 中将变量作为结构构造函数中的引用传递
- 在类构造函数中定义结构变量的参数
- 如何在模板类函数中分配结构值?
- 我应该在C++中将这些结构用作参数化构造函数吗?
- 给定一个C++嵌套的私有结构类型,是否有从文件范围静态函数访问它的策略
- 在结构外部调用指向函数的指针
- 函数:结构的数组
- C++错误:只能为对象和函数结构指定存储类
- 将libuv与函数结构一起使用,而不是函数回调
- 从c#调用c++函数-结构体,指针,函数指针
- 函数结构数组输入cin问题