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 :
template<class T>
class A
{
public:
void doSomething();
void doSomethingToo();
private:
T** data;
//...
};
class AWrapper
{
public:
//Do not explicitly add methods
T* operator->();//Return right pointer based on typeSelector_;
private:
int typeSelector_;
A<char>* charData_;
A<short>* shortData_;
};
template<class T>
class A
{
public:
void doSomething();
void doSomethingToo();
private:
T** data;
//...
};
class AWrapper
{
public:
//Do not explicitly add methods
T* operator->();//Return right pointer based on typeSelector_;
private:
int typeSelector_;
A<char>* charData_;
A<short>* shortData_;
};
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?
Bookmarks