Hey there,
image i have a class called BMPImage. The class looks simplified like this:
Code:
#include "Matrix.h"
class BMPImage
{
public:
BMPImage(const char *filename);
~BMPImage(void);
private:
Matrix<float> *data;
};
data is allocated in the constructor of BMPImage.
The Matrix class looks like this:
Code:
template<typename T>
class Matrix
{
public:
Matrix(const int nRows, const int nCols, const int nChannels);
T get(const int row, const int col);
void set(const int row, const int col, T value);
private:
T *data;
};
data is aswell allocated in the constructor.
BMPImage should have much of the same functionality as a Matrix. This would actually be solved by letting BMPImage inherit from Matrix. This is what i actually want to do.
The problem is, that the two constructors look quite different for Matrix and BMPImage.
What would be an elegant way to implement this?
I think of something like this
Code:
class BMPImage : public Matrix<float>
{
public:
BMPImage(const char *filename)
{
// read the BMP File
// set nRows, nCols of Matrix accordingly to the BMP file
}
};
This would require Matrix to have a default constructor, which would complicate the Matrix class somewhat more than i like to.
Another way would be to implement getters and setters in BMPImage which would simply wrap the getters and setters of the Matrix where the BMP Data is stored.
Any ideas on what solution would be more adequate?
Thanks and best regards, threahdead