Hello, I was just wondering how I can get my classes to work using inheritance and templates, but I have this error:
1 2
classes.cpp: [Error] type/value mismatch at argument 1 in template parameter list for'template<class T, int maxScore> class Championship'
classes.cpp: [Error] expected a type, got 'Player'
Here is my code, any help would be appreciated, thanks.
#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
};
template<class T, int maxScore>
class Player: public Championship<T, maxScore>
{
public:
Player();
private:
int title;
int price;
};
#endif
templateclass Championship<Player<Player, 11>, 11>
Or something similar - I don't know what you're thinking - to me, this is broken.
I doubt that the strong relationship "A player is a championship" implied by the inheritance of Championship from Player is correct. Why is Player a template?
Also -- template definitions must be visible from the point of instantiation. So you need to move the implementation of your templates out of the source file and into the header file -- your code won't link, otherwise.