If you do not want to use a vector, try this ...
MyColor(uint8 (&vec)[3])
{
r = vec[0];
g = vec[1];
b = vec[2];
}
MyColor(uint8 (&vec)[4])
{
//...
}
uint8 a1[] = {1,2,3};
MyColor c1(a1);
uint8 a2[] = {1,2,3,4};
MyColor c2(a2);
uint8 a3[] = {1,2,3,4,5};
MyColor c3(a3); // error
you do not need to explicitly specify the size of the array, and if you try to pass an array with the wrong number of elements, a compilation error will be generated,
source
share