具有模板的结构和功能

问题描述 投票:0回答:1

我刚开始使用模板,并希望以这种方式在我的头文件中实现它,但是我遇到了各种各样的错误,并不真正理解为什么。

头文件:

#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

错误:

Img

c++ templates struct
1个回答
0
投票

我认为您忘了放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
© www.soinside.com 2019 - 2024. All rights reserved.