I look all over the internet and stackoverflow for a specific answer, but I cannot find it. I have to create a generic class and then implement certain functions. My specific instructions were: you need to use template expression options and specialization of template classes 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:
1) Only Z, where x = 2 and y = 2, should have a public method void J ()
2) For char Z x = 2 and y = 2 J will do something; for everything else he does something else
3) Only for Z, where T is char, the array will 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 is not so:
template<int x, int y> Z<char,x,y>::Z<char,x,y>() {
And similarly (suppose J exists) this does not work:
template <class T> void Z<T,2,2>::J() {
My question is:
Is there any simple way to implement the above elements? I need to save all other methods in Z. Giving a hint or pointing in the right direction (maybe I missed the question since there are a lot) would be helpful.
Thanks.