jeudi 26 février 2015

can i cast an unsigned short/int to char *


Hi i have a function like this



void UnitTestWorker::constructTestPayload(QByteArray &payload)
{
QString List = "127.0.0.1";
unsigned short Port = 12344;
unsigned int RequestId = 1;
memcpy(payload.data(),reinterpret_cast<char*>Port,sizeof(Port));
memcpy(payload.data()+sizeof(Port),reinterpret_cast<char*>RequestId ,sizeof(RequestId ));
}


but i am getting access violation error ,seems like i cannot do something like reinterpret_cast<char*>Port or reinterpret_cast<char*>RequestId .


Can someone please tell me how can i correctly do this.


Thanks in advance




Aucun commentaire:

Enregistrer un commentaire