You do not send buffer by reference (or as a pointer to vector<unsigned char>*) when calling read_image`, so the function cannot distribute the update outside the function (i.e. the caller).
This modification of your function will result in what you wish:
void read_image(vector<unsigned char>*& buffer) { buffer = new vector<unsigned char>(2048); }
Now we pass the link as a parameter to read_image , and the original variable will be updated with the value returned with new vector<...> (...) .
If you are a pointer fanatic, this is also true:
void read_image (vector<unsigned char>** buffer) { *buffer = new vector<unsigned char>(2048); } ... read_image (&buffer);
In the above example, we give read_image the address of the pointer itself, and inside we can dereference that pointer to a pointer to set the value that the original pointer points to.
Sorry for the wording, I'm very tired of being honest.
Frequently asked questions regarding the use of links.
source share