I am curious about that why this is illegal. I want to return prepared wxMemoryBuffer object.
Code: Select all
void OnCmd(wxCommandEvent& event){
char *bfr = static_cast<char*>(GetBin().GetData());
printf( "wxMemoryBuffer after return : 0x%02X \n", *bfr);
}
wxMemoryBuffer GetBin(){
wxMemoryBuffer memodata;
char bfr = 0x31;
memodata.AppendByte( bfr );
char *bfrx = static_cast<char*>(memodata.GetData());
printf( "wxMemoryBuffer before return : 0x%02X \n", *bfrx);
return memodata;
}
Code: Select all
wxMemoryBuffer before return : 0x31
wxMemoryBuffer after return : 0x60
I understand that local `memodata` in GetBin() function is destroyed after return, but I am not returning pointer or reference of memodata, I am returning whole object. I thought wxMemoryBuffer will copied to Cmd() function, so GetData() needs work. But it isn't. Whats the point I missYou use a pointer inside the already destroyed wxMemoryBuffer object in OnCmd(), this is a bug in your code.