I have a (partally implemented) class hierarchy where
template<typename T> {
class data {
data ( string s ) {}; // loads from file
...
}
class image: public data <T> {
image ( string s ) {}; // loads from file
...
}
class jpgimage : public image<T> {
jpgimage ( string s ) {}; // loads from file
...
}
// other image types
}
Now in the rest of my code I would like to be able to abstract from whether something is a jpeg image or even an image, so I would like to work with data
. But at the same time I would like to pass commands specific to jpeg images to those functions.
So if I call data<int> img("lena.jpg");
which turns out to be an image, even a jpeg image, I would like the data constructor to call the image constructor, which in turn calls the jpgimage constructor.
There is no way I can get it to work, and people warn about slicing, virtual constructors, etc. But is this such a strange way to set it up?