If I do this, I get "warning: address of local variable returned".
unsigned char* CharArray(void) const
{
unsigned char arr[3];
arr[0] = R_;
arr[1] = G_;
arr[2] = B_;
return arr;
}
So the reason for that is that the memory allocated for arr[] is only available within the scope of the function CharArray?
So instead do I do this:
unsigned char* CharArray(void) const
{
unsigned char* arr = new unsigned char[3];
arr[0] = R_;
arr[1] = G_;
arr[2] = B_;
return arr;
}
Or I could pass a reference and fill it? How would I do that?
void CharArray(unsigned char* &arr)
{
arr[0] = R_;
arr[1] = G_;
arr[2] = B_;
}
main()
{
unsigned char arr[3];
CharArray(arr);
}
Like is it a reference to a pointer? Or is it just
void CharArray(unsigned char &arr)
That seems like it is just a reference to a single unsigned char, not an array of them.
Which is the most modern (ie c++) way to do this?
Thanks!
Dave