I have a sample class where I need to specialize the Print function if the class is of certain type.
But this doesn’t compile at all.
template <typename classType, int size>
class MyVector
{
public:
classType* innerArray;
MyVector(){innerArray = new classType[size];}
~MyVector(){delete[] innerArray;}
void push_back(classType val)
{
innerArray[0] = val;
}
classType& operator[](int index)
{
assert(index >= 0);
return innerArray[index];
}
void Print() {
cout << "Printing Normal" << endl;
}
};
void MyVector<double>::Print()
{
cout << "Printing Double" << endl;
}
MyVectorneeds 2 template parameters, e.g.or else you need to provide a default value for the second template parameter: