templates

I'm currently studying linked lists and had a question about the template implementation. Do I need to include template <typename T> in both the .h and the .cpp. The code is incomplete, but here is what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Node Header */
// CLList.h

#ifndef CLLIST_H_
#define CLLIST_H_

template <typename T>

class CLList
{

public:
  CLList(T);
  ~CLList();
  CLList(CLList<T> &);

private:
  T m_value;
  T *m_next;

public:

// mutators

// accessors
  T getValue() { return m_value; }
  T* getNext() { return m_next; }


}
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* Node Function Definitions */
// CLList.cpp

// Should I include the next line in this file or is the declaration in the .h file enough? */
//template <typename T>   
#include "CLList.h"

CLList::CLList(T value)
:m_value(value)
{

}

CLList::~CLList()
{

}


Any suggestions you can make that will improve my technique, please let me know.


Thanks,

L.
Last edited on
Templates are different. The implementation (yes it needs template) has to be in the same header file as the class definition. In other words, templated classes and functions don't normally go into source files ;)
Last edited on
Thanks! I was curious as the IDE I am using is currently reporting it as a bug (both included and excluded), although I haven't tried compiling the class yet.
Topic archived. No new replies allowed.