Class errors

Would someone be so kind to show me how to eradicate these errors in the below class:

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
/**************************************************************************/
// Set.cpp
#include "stdafx.h"

const int DEFAULT_SET_SIZE = 20;

template <typename T>
class Set
{

	T *data;
    int   current;
    int   limit;
 
	public:

    Set(int  max = DEFAULT_SET_SIZE);

    int isEmpty() const;
    int isFull() const;
	void insert(const char &t);
    char pop();
    const char& top() const;
    void flush();
	
};

Set<T>::Set<T>(int max) 
{
    current = 0;
    limit = max;
    data = new char[max];
}

int Set::isEmpty() const
{
    return current == 0;
}

int Set::isFull() const
{
    return current == limit;
}

void Set::insert(const char &t)
{
    if ( current < limit )
        data[current++] = t;
}

char Set::pop()
{
    if( current > 0 )
        return data[--current];
}

const char & Set::top() const
{
    if ( current > 0 )
        return data[current-1];
}

void Set::flush()
{
    current = 0;
}


Error 1 error C2065: 'T' : undeclared identifier 28
Error 2 error C2065: 'T' : undeclared identifier 28
Error 3 error C2955: 'Set' : use of class template requires template argument list 28
Error 4 error C2509: '{ctor}' : member function not declared in 'Set' 29
Error 5 error C2955: 'Set' : use of class template requires template argument list 35
Error 6 error C2509: 'isEmpty' : member function not declared in 'Set' 36
Error 7 error C2955: 'Set' : use of class template requires template argument list40
Error 8 error C2509: 'isFull' : member function not declared in 'Set' 41
Error 9 error C2955: 'Set' : use of class template requires template argument list 45
Error 10 error C2509: 'insert' : member function not declared in 'Set' 46
Error 11 error C2955: 'Set' : use of class template requires template argument list 51
Error 12 error C2509: 'pop' : member function not declared in 'Set' 52
Error 13 error C2955: 'Set' : use of class template requires template argument list 57
Error 14 error C2509: 'top' : member function not declared in 'Set' 58
Error 15 error C2955: 'Set' : use of class template requires template argument list 63
Error 16 error C2509: 'flush' : member function not declared in 'Set' 64

1
2
3
4
5
6
7
8
9
10
11
12
Set<T>::Set<T>(int max) 
{
    current = 0;
    limit = max;
    data = new char[max];
}

int Set::isEmpty() const
{
    return current == 0;
}



That's not the way you define template class functions.
Take another look at your learning material/book

**Maybe you plan to do it later - but you are going to need a default constructor, copy constructor, assignment constructor/operator and a destructor**
Last edited on
You had this problem before in another post haven't you????????????????
What are these other constructors and why do I need them? and do I not already have a default constructor?

I understand the destructor '~' is for clearing memory, right?

I've cracked the template issue though, thanks anyway
You will likely need them because you have pointers within you class and it looks like you would want to take a deep copy (meaning you copy the array instead of just a pointer to it).
yep, that was what I was talking about.
ok i'll take that in to account...could you provide me with an example of these constructors?
Last edited on
At line 11, it should be:
typename T *data;

You need to use the typename keyword before the type to be able to actually use it as a data type. A more convenient use is:

1
2
typedef typename T myType;
myType *data;

Then you can use the myType data type multiple times without having to continually type typename.
1
2
3
4
5
6
7
8
template <typename T>
void Set<T>::insert(T &t)const 
{         
	

	if ( current < limit )
		data[current++] = t;
}


hello again, how can I make this code check for duplicates in the set?
Last edited on
Topic archived. No new replies allowed.