strcpy not working in C++ but working in C

the code is strcpy(p->data, text);

text is a const char* and p->data is a UDPpacket* from SDL_net.

it works perfectly in C but when the exact same command is called in c++ it gives me this error:

error: invalid conversion from ‘Uint8* {aka unsigned char*}’ to ‘char*’ [-fpermissive]|
/usr/include/string.h|128|error: initializing argument 1 of ‘char* strcpy(char*, const char*)’

Cast p->data as a char pointer.
C++ is more type-strict than C. C is allowing the pointer to be implicitly cast, whereas C++ sees that the types are not similar and gives you an error.

You can explicitly cast to get around the error:

strcpy((char*)p->data, text);  // C-style cast
// or
strcpy( reinterpret_cast<char*>(p->data), text );  // C++ style cast 
thanks, i cannot beleive i didn't solve this myself it is so simple and obvious now. btw, this is for a functioning 3d game i'm writing :)
Topic archived. No new replies allowed.