我刚开始使用模板,并希望以这种方式在我的头文件中实现它,但是我遇到了各种各样的错误,并不真正理解为什么。
头文件:
#ifndef EXAM3_H_
#define EXAM3_H_
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int maxInt = 2147483647;
template <typename T>
struct nodeType {
T data;
nodeType *next;
};
bool search(nodeType *head, const T &searchItem);
void deleteNode(nodeType *&head, nodeType *&tail, int &count, const T &deleteItem);
void initializeList(nodeType *&head, nodeType *&tail, int &count);
bool isEmptyList(const nodeType *head);
void printList(nodeType *head);
int lengthList(nodeType *head);
void destroyList(nodeType *&head, nodeType *&tail, int &count);
void insert(const T &newItem, nodeType *&head, nodeType *&tail, int &count);
#endif
错误:
我认为您忘了放class list
或类似的东西
#ifndef EXAM3_H_
#define EXAM3_H_
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int maxInt = 2147483647;
template <typename T>
class list{
struct nodeType {
T data;
nodeType *next;
};
public:
bool search(nodeType *head, const T &searchItem);
void deleteNode(nodeType *&head, nodeType *&tail, int &count, const T &deleteItem);
void initializeList(nodeType *&head, nodeType *&tail, int &count);
bool isEmptyList(const nodeType *head);
void printList(nodeType *head);
int lengthList(nodeType *head);
void destroyList(nodeType *&head, nodeType *&tail, int &count);
void insert(const T &newItem, nodeType *&head, nodeType *&tail, int &count);
};
#endif