<分区>
我正在尝试创建一个链表,但是当我运行 IsEmpty(test) 时,它只是说它没有在此范围内声明,即使它是公开的。
我是模板方面的新手,但我无法在谷歌上找到答案,所以我不得不在这里提问。有人知道问题出在哪里吗?
此外,错误指向我调用 IsEmpty() 的 main()
//.h
template <typename ItemType>
class Node
{
public:
ItemType Data;
Node <ItemType> *next;
int position;
};
template <typename ItemType>
class Linked_List
{
public:
Node <ItemType> *start;
Linked_List();
bool IsEmpty();
}
//.cpp
#include "Linked_List.h"
#include <iostream>
#include <cstdlib>
using namespace std;
template <typename ItemType>
Linked_List <ItemType>::Linked_List(){
start = NULL;
}
template <typename ItemType>
bool Linked_List <ItemType>::IsEmpty(){
if (start == NULL){
return true;
}
return false;
}
int main(){
Linked_List <int> test;
cout << IsEmpty(test) << endl; //error points to here
}