invalid use of template name without an argument list

落花浮王杯 提交于 2020-02-26 05:52:28

问题


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

and this is my implementation code:

#include "LinkedList.h"

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

LinkedList::~LinkedList()
  {

  }

回答1:


Write it like this:

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.



来源:https://stackoverflow.com/questions/18186878/invalid-use-of-template-name-without-an-argument-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!