/**************************************************************************/
// Set.cpp
#include "stdafx.h"
constint 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(constchar &t);
char pop();
constchar& top() const;
void flush();
};
Set<T>::Set<T>(int max)
{
current = 0;
limit = max;
data = newchar[max];
}
int Set::isEmpty() const
{
return current == 0;
}
int Set::isFull() const
{
return current == limit;
}
void Set::insert(constchar &t)
{
if ( current < limit )
data[current++] = t;
}
char Set::pop()
{
if( current > 0 )
return data[--current];
}
constchar & 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
Set<T>::Set<T>(int max)
{
current = 0;
limit = max;
data = newchar[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**
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).