#ifndef CLASSES_H
#define CLASSES_H
template<class T, int maxScore>
class Championship
{
public:
Championship(int, constchar*); //Passes through game type and number of games
private:
char *compType;
T *t; //Teams or Players
};
#endif
Championship.cpp:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include "classes.h"
usingnamespace std;
template<class T, int maxScore>
Championship<T, maxScore>::Championship(int s, constchar* name)
{
//Code Here
}
A template class is ignored until it is used with its template parameter (line 9 in main.cpp). At that point the compiler sees only the declarations within classes.h and not the definitions in Championship.cpp. Therefore the templated defintions won't be include in the compiler process.
Championship<Player, 11>::Championship(int s, constchar* name)
{
//Code Here
}
(assuming you have defined Player someplace and linking Championship.cpp with main.cpp)
else
1 2 3 4 5 6 7 8 9 10
template<class T, class U>
class Championship
{
public:
Championship(int, constchar*); //Passes through game type and number of games
private:
char *compType;
T *t; //Teams or Players
};
and
1 2 3 4
Championship<Player, int>::Championship(int s, constchar* name)
{
//Code Here
}