I have been looking all over the internet and stackoverflow for a concrete answer but I can't seem to find one. I have to create a generic class and then implement specific functions. My specific instructions were: You need to make use of Template Expression Parameters and Template Class Specialization and Partial Specialization.
I have a template class:
template <class T, int x, int y>
class Z {
T **array[x][y];
public:
Z();
void print();
//and other methods
};
I need to:
1) Only Z's where x= 2 and y = 2 need to have a public method void J()
2) For char Z's of x = 2 and y= 2 J will do something; for everything else it does something else
3) For only Z's where T is char will the array be initialized to some value. For everything else it's 0
Naturally, this works:
template<class T, int x, int y>
Z<T,x,y>::Z<T,x,y>() { //initialize to 0 }
But this doesn't:
template<int x, int y>
Z<char,x,y>::Z<char,x,y>() { //initialize to something}
And likewise (assume J exists) this does not work:
template <class T>
void Z<T,2,2>::J() { //something }
My question is:
Is there any simple method for implementing the above items? I need to keep all the other methods in Z. Giving a hint or pointing in the right direction (maybe I missed a question since there are a lot) would be helpful.
Thanks.
J? It is not clear what you want to do. - Synxisclass Z<char, x, y>'" and "template definition of non-templatevoid Z<char, x, y>::J()' " - aoi