没有参数列表的模板名称的无效使用 [英] invalid use of template name without an argument list

查看:106
本文介绍了没有参数列表的模板名称的无效使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的链表类遇到问题,我已经创建了该类的接口和实现文件,但是在构建它时,会发生此错误:模板名称'LinkedList'的无效使用,没有参数列表 。
这是我的界面文件:

I am facing a problem with my linked list class, I have created the interface and implementation files of the class, but when I build it, this error occurs: "invalid use of template name 'LinkedList' without an argument list". here's my interface file:

#ifndef LINKEDLIST_H
#define LINKEDLIST_H

template <typename T>
struct Node{
    T info;
    Node<T> *next;
};

template <typename T>
class LinkedList
{
    Node<T> *start;
    Node<T> *current;
public:
    LinkedList();
    ~LinkedList();
};

#endif // LINKEDLIST_H

这是我的实现代码:

#include "LinkedList.h"

LinkedList::LinkedList()
{
   start = nullptr;
   current = nullptr;
}

LinkedList::~LinkedList()
  {

  }


推荐答案

像这样写:

template<typename T>
LinkedList<T>::LinkedList()
{
   start = nullptr;
   current = nullptr;
}

其他成员函数也是如此。但是您会遇到另一个问题-模板的声明和定义不能分开到其他文件。

And similarly for other member functions. But you'll run into another problem - declarations and definitions of a template can't be separated to different files.

这篇关于没有参数列表的模板名称的无效使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆