Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot initialize a parameter of type "const unsigned char *" with an rvalue of type 'value_type *' (aka char*)

Tags:

c++

c

cocos2d-x

I get an error "Cannot initialize a parameter of type "const unsigned char *" with an rvalue of type 'value_type ' (aka char)" in the following lines.

image->initWithImageData(&(buffer->front()),buffer->size());

buffer is of type std::vector<char> *buffer

and the above error in on &(buffer->front() does anybody know how to fix it?

like image 710
Geo Paul Avatar asked Oct 19 '25 10:10

Geo Paul


1 Answers

The const is not a problem, but you need to cast the pointer - this isn't recommended generally but if you don't have another choice, you can do one of the following

char *a = buffer->data();
const unsigned  char *b= reinterpret_cast<unsigned char *>(a);

or plain C style

const unsigned  char *b= (const unsigned  char *)(a);
like image 171
Ophir Gvirtzer Avatar answered Oct 21 '25 00:10

Ophir Gvirtzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!