So, I've been struggling with this bit. I have a simple function, that is defined as follows:
const unsigned char GetColor(unsigned int x, unsigned int y)
{
const unsigned char color[3] = {0, 1, 0};
return color;
}
Yet, I am not allowed to do this and the compiler returns with the following error:
Error: cannot initialize return object of type 'const unsigned char' with an lvalue of type 'const unsigned char [3]'
Should I convert the array into a pointer to an array, which I should return? If I do this, don't I risk that it may be deleted after going "out of scope" - aka out of the function?
Any help in understanding this problem will be greatly appreciated :)
EDIT: The end goal is to have a function, that can return a color at a pixel location, given an x- and y value. That means that color changes, depending on the value of x- and y. The example above is a simplification.
It should return an const unsigned char array of size 3, with a value in each.