I've been told that a class' memory always has the same structure:
So if I have the pointer to a member of a class, can I somehow calculate the pointer to that class?
class num
{
public:
num() {}
int a;
int b;
};
int* ptr; // we have the pointer to num.b
num* number; // we want the pointer to num
Would it be possible to get "number" with only "ptr"? Something like this:
num temp;
int diff = (void*)&temp - (void*)&temp.b;
num target;
int* ptr = &target.b;
num* number = (num*)((void*)ptr + diff);