What I really wanted was a single class, ImageSegmentation<T> that operates on images of type T. The problem was that this object needed to be a member of my Qt form object (called Form), but I didn't know T until runtime (the user selects which type of image to operate on. Because of that, I structured it like this:
ImageSegmentationBase - functions that don't depend on T
ImageSegmentation<T> : public ImageSegmentationBase - function which depend on T.
Then I member variable of Form:
ImageSegmentationBase* MyImageSegmentation;
I instantiate it with
MyImageSegmentation = new ImageSegmentation<T>;
The problem now is that I can't get the data out! From a function Form::function() I want to do:
Form::function()
{
T image = MyImageSegmentation->GetData();
... continue processing image normally...
}
Of course GetData can't be defined in ImageSegmentationBase because the return type is T. It can be defined no problem in ImageSegmentation<T>, but I don't know T inside Form::function()!
I tried to put a typedef inside ImageSegmentationBase:
template<class T>
struct ImageSegmentationBase{
typedef T type;
};
To then do
Form::function()
{
MyImageSegmentation::type image = MyImageSegmentation->GetData();
}
but it says "ImageSegmentation is not a namespace".
Is there a way to do something like this? It seems like a pretty standard pattern, no?
Thanks,
David