A template class is just that: a template for a class. It doesn't create a real class until you give it template parameters to use. Let's say you have a class C:
Code:
class C {
int val;
public:
C ( int init ): val ( init ) {}
int get() const { return val; }
};
All is well and good, right? Now let's say you want class C to handle both int and char. You can make it a template class:
Code:
template <typename T>
class TC {
T val;
public:
C ( T init ): val ( init ) {}
T get() const { return val; }
};
Everything is the same except int is replaced with T. Keep in mind that class C is a real class right now, but class TC is just a template. The class doesn't actually exist until you specialize it with a type for T. So when you do this:
Code:
TC<int> obj1;
TC<char> obj2;
Two classes are created for int and char (and one object of each is instantiated):
Code:
template<>
class TC<int> {
int val;
public:
TC ( int init ): val ( init ) {}
int get() const { return val; }
};
template<>
class TC<char> {
char val;
public:
TC ( char init ): val ( init ) {}
char get() const { return val; }
};
The only change is the types used. All of the behavior of the original class remains the same. The problem with your code is that you are mixing up template parameters and constructor arguments.