class SomeClass
{
public:
int SomeFunc();
virtual void DoSomeThing();
void Copy(MyContainer* container)
{
//Is this line OK?
//why not memcpy(container->data, this, sizeof(SomeClass) ?
memcpy(&container->data, this, sizeof(SomeClass));
}
SomeClass* GetFromCopy(MyContainer* container)
{
//And this ?
return (KLunaBase*)&container->pData;
}
void Test()
{
MyContainer* cont = NULL;
container = malloc(sizeof(cont) - sizeof(cont->data) + size);
Copy(cont);
}
private:
int a;
int b;
SomeOtherClass objA;
}
struct MyContainer
{
const void* data;
}
I have read some historic code, which simplified above, the function Copy
and GetFromCopy
I could not understand.
I know that POD class can copy, but what if the class have virtual function and reference member object ?
sorry for my poor English.