No, unsigned chars are implicitly convertible to all other integer types.
Also, what if a letter is passed to a constructor
Letters are valid colors, since colors are numbers and letters are numbers. You can pass letters to the constructor of your RGBA class. Go ahead, try it.
BTW: operators:
1 2 3 4 5 6 7 8 9
struct RGBA{
unsignedchar r, g, b, a;
booloperator==(const RGBA &other) const{
return r == other.r && g == other.g && b == other.b && a == other.b;
}
booloperator!=(const RGBA &other) const{
return !(*this == other);
}
};
#include <iostream>
#include <cassert>
#include <limits>
static_assert( std::numeric_limits<unsignedchar>::max() == 255, "unexpected range for unsigned char" ) ;
void poor_style( unsignedchar a ) // invariant: 0 <= a <= 255
{
assert( a >= 0 && a <= 255 ) ; // meaningless
// *** warning: comparison is always true due to limited range of data type
std::cout << "poor_style( " << int(a) << " )\n" ;
}
int main()
{
int value ;
std::cin >> value ; // 428 or -45
// requires validation by user code to avoid a silent logical error
poor_style(value) ; // this val;idation would be required at every place in user code where the function is called
}
Even in the implementation, unless space is of paramount importance, consider using (signed) int
Evaluation of (most) expressions would require the implicit conversion (promotion) of unsigned char to int.