struct Base
{
virtual void func() = 0;
};
struct A : Base
{
void func()
{
std::cout << "a: " << a << "\n";
}
int a;
};
int main()
{
A a;
a.a = 1;
A a2 = a;
A a3;
char * ap = reinterpret_cast<char*>(&a);
char * ap2 = reinterpret_cast<char*>(&a2);
char * ap3 = reinterpret_cast<char*>(&a3);
for (int i = 0; i < sizeof(A); ++i)
*(ap3 + i) = *(ap + i) ^ *(ap2 + i);
Base * b = &a3;
b->func();
}
I want to bitwise xor the contents of an object with virtual functions like above.
But I think i get a crash in above scenario because I xor'd the vptr too.
Is there a way to achieve what I want?
↧