class with templates

Hi everyone,

I have a class that plays the role of a list and I am having some difficulties on some functions:
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
template <typename TYPE>
class OrderedCollection
{
protected:
 int container_size, container_capacity;
 TYPE* content; 

public:
// default constructor
// copy constructor
// and many more
const TYPE&   front () const;
const TYPE&   back  ()const;
};

//
// my question is, Is this ok, for some reason it does not look right.
// I canot test the code to check I have to write it for now and then test it.
const TYPE& OrderedCollection <TYPE>::front()const
{
	TYPE temp; // create a temporary onj to acces the content 

// [0] is the front of the OrderedCollection(array)

	return(temp.content[0]);

        // or this way???
        //return content[0];
}

// same with this
template <typename TYPE>
const TYPE& OrderedColection <TYPE>::back()const
{
	TYPE temp;

	for(int i= 0; i <= container_size; ++i)
	{
		int var = i;
	}

	return(temp.content[i]);

        // or this way??? like above
        // return content[i];
}


thanks in advance for the help and ideas
Last edited on
?
Defining a function template requires template <typename TYPE> before the function definition, like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
template <typename T>
class X
{
    public:
        void Function();
};

// Definition:
template <typename T>
void X<T>::Function()
{
    //...
}


Wazzak
Last edited on
Thanks for the reply,

I am a ware of the decleration in front of the function, that was a typo error on my part

but I was wondering abot the code in the body if it was correct and which aproach is the right one...
Topic archived. No new replies allowed.