   c++ Image class: Support multiple Pixel Formats..
  Hi,I am currently writing a small Image class and I would like to support different Pixelformats. Here are some Format examples:typedef Color3<ColorRGB<uint8> > ColorRGB8;typedef Color3<ColorRGB<uint16> > ColorRGB16;typedef Color3<ColorRGB<uint32> > ColorRGB32;typedef Color4<ColorRGBA<uint8> > ColorRGBA8;typedef Color4<ColorRGBA<uint16> > ColorRGBA16;typedef Color4<ColorRGBA<uint32> > ColorRGBA32;Here is how I want to represent the pixel array inside my image class, i.e. if the format was ColorRGB8: typedef Grid<ColorRGB8> PixelGridRGB8;Where Grid is a simple wrapper around std::vector to allow to get values by get(size_t _x, size_t _y).That all seems to work, anyways my actual problem is this. I want to have a generic Image class which works like this:Image myImage;myImage.load("test.png");//_______________________________________//or the following if you want to force a pixel formatmyImage.load("test.png", PixelFormats::RGB8);//then I would like to be able to do thisPixelGridRGB8 & pixels = myImage.getPixelGrid();for(uint32 x=0; x<myImage.getWidth(); ++x){ for(uint32 y=0; y<myImage.getHeight(); ++y) {   // do something }}This means that the internal representation of the pixels get's decided at runtime and since I can't set a template argument at runtime there is no way I can specify the Grid<Template Argument> while loading the image. My Idea was to create an abstract PixelGrid baseclass to solve the problem, but then I would propably need to create an abstract baseclass for my Color definitions aswell and things would become utterly complex. The problem seemed to be so easy to solve in the beginning but now I am completely lost so I'd be happy about some ideas!EDIT:Okay, I am pretty certain now, that if I want to stick with this, there is not really a way around using a cast. I made an empty PixelGrid baseclass and the image class basically stores a pointer to that. this is how it looks right now:struct PixelGrid{virtual ~PixelGrid() {}};template<class TPixelType>class GenericPixelGrid : public PixelGrid, Grid<TPixelType>{public:typedef TPixelType ValueType;GenericPixelGrid(){}GenericPixelGrid(size_t _width, size_t _height):Grid<TPixelType>(_width, _height){}};class Image{protected:   //....PixelGridPtr m_pixelGrid;   ///....public: //....PixelGridPtr getPixelGrid() { return m_pixelGrid;}//....Then I can get the pixel grid like this:PixelGridRGB8 * grid = static_cast<PixelGridRGB8*>(img.getPixelGrid());well, it's not very safe or straight forward, so I am still very much looking for some input!   