I have the following two objects. Im wondering if there is a way to have Pixel
as a base class of PixelBGR
so that any operator (+,-,*,/, [], etc.) could be used without redefining them ?
template<class T, std::size_t N>
struct Pixel
{
T ch[N];
inline T& operator[](const int x)
{
return ch[x];
}
};
template<class T>
struct PixelBGR
{
union
{
struct
{
T b;
T g;
T r;
};
T ch[3];
};
inline T& operator[](const int x)
{
return ch[x];
}
};
EDIT: As suggested by πάντα ῥεῖ, here more details about what Im trying to do.
Im trying to have a generic class Pixel
, which will be template to handle any type or size.
The usual are 1,2,3,4,8 or 16. The class with defines some operator
such as +,-,*, etc.
Since most of the time, the Pixel<T,3>
is a BGR pixel, I would like to define rapid access to r
,g
and b
to avoid confusion, but still store it as BGR.
But the derived class should also provide the Operator which will be generic based on N
.
EDIT2: By reading the comment of SergeyA, I forgot to say that the struct Pixel
must not change size.
So I think balki answer is the best, by using member function. I was trying to make it with variables to avoid too much char ie: adding the (), but it seems to be too complicated for nothing. I still investigating CRTP, but I dont get it well, Im reading on that.