Error C2244 unable to match function definition with existing declaration

I am trying to create a simple list of templates in C ++, Visual Studio 2010 & amp; I get: error C2244 is unable to match function definition with existing declaration.

I tried changing it to 'typename', but that didn't help.

This is a basic list of templates with basic functions (Ctor, Dtor, Add, Delete).

Please, help.

#ifndef LIST_H_
#define LIST_H_

template <typename T>
class Node
{
    T* m_data;
    Node* next;
public:
    Node(T*, Node<T>*);
    ~Node();
    void Delete (Node<T>* head);
};

template <typename T>
Node::Node(T* n, Node<T>* head)
{ 
    this->m_data = n;
    this->next=head;
}

template <typename T>
void Node::Delete(Node<T>* head)
{
    while(head)
    {
        delete(head->m_data);
        //head->m_data->~data();
        head=head->next;
    }
}

template <typename T>
class List
{
    Node<T*> head;
public:
    List();
    ~List();
    void addInHead (T*);
};

template <typename T>
void List :: addInHead (T* dat)
{
    head = new Node<T*> (dat,head);
}

template <typename T>
List::List()
{
    head = NULL;
}

template <typename T>
List :: ~List()
{
    head->Delete(head);
}

  #endif

You have the code above.

+5
source share
1 answer

Your syntax for implementing template functions outside the template body is incorrect. It should be like this:

template <typename T>
Node<T>::Node(T* n, Node<T>* head)
//  ^^^----- You need to add <T> here
{ 
    this->m_data = n;
    this->next=head;
}

You also lack the destructor definition for Node:

template <typename T>
Node<T>::~Node()
{
    ... // Clean-up code 
}

Link to ideon.

+10
source

All Articles