hello!
I'm writing a C++ program and I have to use memcpy at some point.
I will explain my problem:
I have a simple struct named A and a class named B and I do the following:
Code:
class B{
//private variables
public:
A* a1;
void* pVoid;
}
A a2;
a2=//assign a2 with a value
Now,at some point of my program I have an object of type B
and memcpy works fine.
Code:
B b1;
memcpy((void*)((char*)b1.pVoid,(void*)&a2,sizeof(A));
In another part of my program I have a pointer to an object of type B
as I call a function in which I send an object of type B like this:
function(&b1);
and when I get the results of memcpy it returns garbage or memory addresses,but not the value of a2 as it does above.So I think it must be pointer's fault..
Code:
function(B *b2){
memcpy((void*)((char*)b2->pVoid,(void*)&a2,sizeof(A));}
Does anybody have any idea how to fix it?