common problems templating a class? stuck

I'm trying to template a class and I'm having some problems. I did everything that my instructor and our book suggested.

Here is what my header looks like:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

#include <list>

#ifndef TRINODE_H
#define TRINODE_H

template <class myType>
class trinode
{
public:

	//CONSTRUCTOR//
	trinode(myType init_data =0);
	//Creates a trinode containing specified data_field or default 0

	//MEMBER FUNCTIONS//

	void set_data(myType new_data);
	//sets the data_field in the root
	void insert_node(const myType&entry);
	//Member Function to insert a new node in any direction
	void remove_head(std::string direction);
	//Member functions to remove a node from the begin of list
	void remove_tail(std::string direction);
	//Member functions to remove a node from the end of list


	//CONSTANT MEMBER FUNCTIONS//

	int data() const;
	//const member functions to retrieve current data:

	//Member functions to retrieve links:
	const std::list<myType>* left() const;
	std::list<myType>* left();
	const std::list<myType>* right() const;
	std::list<myType>* right();
	const std::list<myType>* down() const;
	std::list<myType>* down();


private:
	myType data_field;
	std::list<myType>* left_link;
	std::list<myType>* right_link;
	std::list<myType>* down_link; 
};

#include "trinode.cpp"
#endif 


I dont want to post the entire implementation and take up a ton of space since most of the errors are probably repeating, but heres what the beginning of it looks like:

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <string>

//CONSTRUCTOR: Creates a trinode containing specified initial values
template <class myType>
trinode<myType>::trinode(myType init_data)
{
	data_field = init_data;

	left_link = new std::list<myType>;
	right_link = new std::list<myType>;
	down_link = new std::list<myType>;
}


//Member functions to set the data
template <class myType>
void trinode<myType>::set_data(myType new_data)
{
	data_field = new_data;
}



//Member Function to insert a new node at the end of a list
template <class myType>
void trinode<myType>::insert_node(const myType&entry)
{
	if(entry > data_field)
	{
		right_link->push_back(entry);		
	}

	else if(entry < data_field)
	{
		left_link->push_back(entry);
	}
	else
	{
		down_link->push_back(entry);
	}

}


//Member functions to remove a node from the end/begin of list
template <class myType>
void trinode<myType>::remove_head(std::string direction)
{
	direction[0] = tolower(direction[0]);

	if(direction == "right")
	{
		right_link->pop_front();	
	}

	if(direction == "left")
	{
		left_link->pop_front();		
	}

	if(direction == "down")
	{
		down_link->pop_front();	

	}
}



Do I have any super obvious errors that people generally have when templating a class? This is the first time ive done one.
Whenever you have: std::list<myType> you need to change it to: std::list<typename myType>.
when I changed it to include the typename I got the same errors as when I run it without lol
anyone know why I would get the error C2988 on all of my functions?
"error C2988: unrecognizable template declaration/definition"
change your trinode.cpp file to some other name like trinode.inl
(and obvioulsy change the line in the trinode.h file to say #include "trinode.inl" instead of #include "trinode.cpp")
Last edited on
Topic archived. No new replies allowed.