I have two classes: dot and pixel:
class point {
public:
point(int x, int y) : x(x), y(y) { };
private:
int x, y;
}
template <class T>
class pixel : public point {
public:
pixel(int x, int y, T val) : point(x, y), val(val) { };
private:
T val;
}
Now here is my problem. I want to create a container class (let it be called coll) that has a private vector of dots or pixels. If the coll instance contains pixels, I want it to have a toArray () method that converts the vector of the vector to an array from T representing the contents of the vector.
I was going to do this with inheritance: i.e. I could create a base class coll containing a point vector and a derived class that contains an extra method, but then I seem to run into problems, since a pixel is a template class.
Does anyone have any suggestions? Can I do this somehow by creating a class template?