I am getting this error in Visual Studio 2010 Pro: “Error C2953: ‘list_1::Node’ : class template has already been defined”
Here is my Node.cpp class list that is getting the error (on line 24, the last line of the code.)
#include "Node.h"
namespace list_1
{
template <typename T>
struct Node
{
//Constructor
Node<T>(T D)
{
data = d;
next = NULL;
}
}
;}
And the Node.H file:
#pragma once
namespace list_1
{
template <typename T>
struct Node
{
T data;
Node<T> *next;
// Constructor
// Postcondition:
Node<T> (T d);
};
}
I already looked here, which doesn’t help me since I am already using #pragma once, and in the list header file I have #ifndef LIST_H and #define LIST_H. This question doesn’t suit my needs and everything in this answer seems to be related to having the template bit that I already have.
If I try making it struct Node I get the error “error C2753: ‘list_1::Node’ : partial specialization cannot match argument list for primary template”
So I am at a loss at what to do. Please help.
I agree with your compiler.. You are defining the
structtwice.To fix –
Remove from your header.
And your .cpp should look like this.
Essentially, the struct block only appears in the header.
Additionally I wonder if you are aware of the problems involving defining the template classes members in a
.cppfile