Hello,

I'd like to specialize a method in a template class for another generic template class and can't figure out how to do it exactly.
The simplified code looks like this:
Qt Code:
  1. template<typename T>
  2. class ClassA
  3. {
  4. public:
  5. ClassA(){...}
  6. ~ClassA(void){...}
  7. ClassA(const ClassA<T> &other){...}
  8. ClassA<T>& operator=(const ClassA<T> &other){...}
  9.  
  10. inline T& operator() (int height, int width){
  11. if (height < 0 || height >= getHeight() || width < 0 || width >= getWidth())
  12. ...
  13. else
  14. return _pMat[height][width];
  15. }
  16.  
  17. inline T operator() (int height, int width) const{
  18. if (height < 0 || height >= getHeight() || width < 0 || width >= getWidth())
  19. ...
  20. else
  21. return _pMat[height][width];
  22. }
  23. inline int getWidth(void){return _iWidth;}
  24. inline int getWidth(void) const{return _iWidth;}
  25. inline int getHeight(void){return _iHeight;}
  26. inline int getHeight(void) const{return _iHeight;}
  27.  
  28. void print(void){
  29. std::cout << "print general" << std::endl;
  30. }
  31.  
  32. private:
  33. int _iWidth;
  34. int _iHeight;
  35. T** _pMat;
  36. };
  37.  
  38. template<>
  39. void ClassA< ClassB<int> >::print(void){
  40. std::cout << "print specialized <int>" << std::endl;
  41. }
  42.  
  43. template <typename U>
  44. class ClassB
  45. {
  46. public:
  47. inline ClassB(){...}
  48. inline ~ClassB(void){...}
  49. inline ClassB(const ClassB<U> &other){...}
  50. inline ClassB<U>& operator=(const ClassB<U> &other){...}
  51. inline U& operator() (int dimension){
  52. if (dimension >= 0 && dimension < getDimension())
  53. return _pData[dimension];
  54. else
  55. ...
  56. }
  57. inline U operator() (int dimension) const{
  58. if (dimension >= 0 && dimension < getDimension())
  59. return _pData[dimension];
  60. else
  61. ...
  62. }
  63. inline int getDimension(void) const{return _iDimension;}
  64. inline int getDimension(void){return _iDimension;}
  65. inline void print(void){...}
  66.  
  67. private:
  68. int _iDimension;
  69. U *_pData;
  70. };
To copy to clipboard, switch view to plain text mode 

if I instantiate the templates like this:
Qt Code:
  1. ClassA< ClassB<int> > test;
  2. test.print();
To copy to clipboard, switch view to plain text mode 
everything works as desired and the specialized print method is called when ClassB is of type <int>.

but I also need specialized methods for:
Qt Code:
  1. ClassA< ClassB<double> > test1;
  2. ClassA< ClassB<float> > test2;
  3. //etc...
To copy to clipboard, switch view to plain text mode 

so I'd like to spezialize my print method like this:
Qt Code:
  1. template<>
  2. void ClassA< ClassB<U> >::print(void){
  3. std::cout << "print specialized <U>" << std::endl;
  4. }
To copy to clipboard, switch view to plain text mode 

I hope this is possible, and I think I'm missing some template syntax to make it work.

I hope someone knows how to do it...

thanks in advance
darksaga