I'm having a lot of problems converting my Set class into a template class. I have commented out all of the code other than the constructors and cannot get it to work. I have a header file and cpp file. Any advice?
I used the solutions from the other thread, but am unable to make it work.
Note: I only included the constructors from my cpp file since I'm working on that first.
Header file:
#ifndef SET_H
#define SET_H
#include <iostream>
using namespace std;
template <class T>
class Set {
//friend istream& operator>>( istream& in, Set& set );
//friend ostream& operator<<( ostream& out, Set& set );
public:
/*bool operator+( const T& rhs );
Set operator+( const Set& rhs );
bool operator-( const T& rhs );
Set operator-( Set& rhs );
Set operator^( Set& rhs );
bool operator==( Set& rhs );
bool operator!=( Set& rhs );
*/
Set();
Set( T2 [], int, char );
Set( const Set& );
/*~Set() {
delete elements;
elements = NULL;
numElements = pSize = 0;
}
int length() const;
T getElement( int ) const;
void display();
void checkUp();
bool add( T );
bool contains( T );
bool remove( T );
int findCell( int, T );
*/
private:
static const int DEFAULT_SIZE = 5;
static const int emptyCell = -99999;
char name;
int pSize, numElements;
int *elements;
};
cpp File:
#include "set.h"
template < typename T >
template <class T2> Set::Set() {
elements = NULL;
pSize = numElements = 0;
}
template <class T2> Set::Set( T2 array[], int ps, char nm ) {
elements = NULL;
pSize = numElements = 0;
//For each member of array, we're going to add it to this
/*
for ( int i = 0; i < ps; i++ )
this->add( array[ i ] );
name = nm;
*/
}
template <class T2> Set::Set( const Set& s ) {
elements = NULL;
pSize = numElements = 0;
/*For each member of the passed set, we're going to add to this
for ( int i = 0; i < s.length(); i++ )
this->add( s.getElement( i ) );
*/
}
Thanks!!