I have two classes, point 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's my problem. I want to make a container class (let's call it coll) that has a private vector of points or pixels. If an instance of coll contains pixels, I want it to have a method toArray(), which converts its vector of pixels to an array of T representing the contents of the vector.
I was going to do this with inheritance: ie, I could make a base class coll that contains a vector of points and a derived class that contains the extra method, but then I seem to run into problems since pixel is a class template.
Does anyone have suggestions? Could I do this somehow by making coll a class template?