Use of Class Template Requires Template Argument List

Nov 6, 2013 at 5:58pm
I'm not sure why I am getting these errors. I've looked all over the forums and tried everything I can think of to fix them. any help would be greatly appreciated! Also I hope this is enough info:

Error 1 error C2955: 'DoubleLinkedListInterface' : use of class template requires template argument list \doublelinkedlist.h 10
Error 2 error C2244: 'DoubleLinkedList<T>::DoubleLinkedList' : unable to match function definition to an existing declaration doublelinkedlist.cpp 7

Error 3 .cpp error C2244: 'DoubleLinkedList<T>::~DoubleLinkedList' : unable to match function definition to an existing declaration 12

.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once

#include "DoubleLinkedListInterface.h"
#include "Node.h"
#include <iostream>


template <class T>
class DoubleLinkedList : DoubleLinkedListInterface
{
		
public:
	DoubleLinkedList( void ){}
	
	virtual~DoubleLinkedList( void ){}


.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13

#include "DoubleLinkedList.h"
#include <iostream>

template <class T> 
DoubleLinkedList::DoubleLinkedList(void)
{
}

template <class T> 
DoubleLinkedList::~DoubleLinkedList(void)
{
}
Nov 6, 2013 at 6:04pm
You cannot provide template definitions in cpp files, all aspects of templates must be defined in the header.
Nov 6, 2013 at 6:05pm
1) You've already included a body for your constructor and destructor in the header file, so your definition is in there. Why are you trying to create a second definition in a cpp file?

2) Regardless, you can't split the definition of a template class between a header and cpp file in the same way as for a normal class. The entire definition has to be within the header file.
Nov 6, 2013 at 6:11pm
If you'll notice i'm including the DoubleLinkedListInterface in the .h. Also I'm novice at classes so I don't completely understand specifications when it comes to .h and cpp dealing with templates etc.

Also by including iostream in the .cpp a bunch of errors were eliminated. I thought i could include the iostream in the .h and then just include the .h in m .cpp and it would automatically recognize the iostream but it didn't.

"You cannot provide template definitions in cpp files, all aspects of templates must be defined in the header"

If I remove the template definitions to the .cpp by removing the template definition I get another error
4 IntelliSense: argument list for class template "DoubleLinkedList" is missing DoubleLinkedList.cpp 5
1
2
3
4
5
6
7
8
DoubleLinkedList::DoubleLinkedList(void)
{
}


DoubleLinkedList::~DoubleLinkedList(void)
{
}

Last edited on Nov 6, 2013 at 6:15pm
Nov 6, 2013 at 6:18pm
OJ007 wrote:
I'm novice at classes so I don't completely understand specifications when it comes to .h and cpp dealing with templates etc.
There is little to understand: if you're using templates, do not use .cpp
Topic archived. No new replies allowed.