その構造体への二重ポインターを指定して、データを構造体メンバーにコピーしたいと考えています。の署名を変更できませんcopyFoo()。メンバ cnt にはGetCnt()期待どおりの戻り値が割り当てられますが、memcpyこのように使用するとアクセス違反が発生します。構造体への二重ポインターと void ポインター メンバーがある場合に memcpy を使用する方法を詳しく説明してもらえますか? どうもありがとうございました!
struct mystruct
{
void * data;
unsigned int cnt;
};
void copyFoo( myObj * inBar, mystruct **outFoo)
{
memcpy((*outFoo)->data, inBar->GetData(), inBar->GetLength() );
(*outFoo)->cnt= inBar->GetCnt();
}
int main(void){
myObj *in = getObj();
mystruct *out= new mystruct;
copyFoo(in, &out));
delete in;
delete out;
}
のmemberfunctionGetData()はinbarvoid ポインターをGetCnt()返しunsigned int、 をGetLength()返し、 を返しますint。