I have a template class with a lot methods for 3D operations, to be able to perform the operations on different types T(for the moment only unsigned char and unsigned short). I would like to set the type of the 3D array of a certain type T, be able to perform a lot of operations on this data regardless of the type and retrieve the type when I need type-related data from it (for example a slice of the volume).

Currently I create a class with pointers to instantiations of the classes with all possible data types, a selector to determine the current type, and I add a method for each underlying method of the template class, which calls the right version. This seems quite cumbersome, and needs a change of the wrapper implementation each time the template class is changed.

Is there a way to do something like the following :

Qt Code:
  1. template<class T>
  2. class A
  3. {
  4. public:
  5. void doSomething();
  6. void doSomethingToo();
  7. private:
  8. T** data;
  9. //...
  10. };
  11.  
  12. class AWrapper
  13. {
  14. public:
  15. //Do not explicitly add methods
  16. T* operator->();//Return right pointer based on typeSelector_;
  17. private:
  18. int typeSelector_;
  19. A<char>* charData_;
  20. A<short>* shortData_;
  21. };
To copy to clipboard, switch view to plain text mode 

Off course this does not work since T is still undefined in the wrapper. Any way to accomplish this?