Play harder

This commit is contained in:
Attila Body 2024-04-08 16:52:54 +02:00
parent 8ae1c4e9eb
commit d78b1a852a
No known key found for this signature in database
GPG key ID: 3D2FC6085E166F70

View file

@ -5,15 +5,23 @@
#include <stdint.h>
#include <iostream>
#include <stdio.h>
using namespace std;
class C
{
public:
C() = default;
virtual ~C() = default;
void foo(int bar)
{
cout << reinterpret_cast<uintptr_t>(this) << " -> " << bar << endl;
printf("%p -> %d\n", this, bar);
}
virtual void fooo(int bar)
{
printf("%p -> %d\n", this, bar);
}
};
@ -24,10 +32,15 @@ int main(int argc, char **argv)
{
C c;
cvifptr_t zup = &C::foo;
cout << zup << endl;
vifptr_t baz = reinterpret_cast<vifptr_t>(zup);
cout << baz << endl;
void (C::*mfp)(int) = &C::foo;
vifptr_t biz = reinterpret_cast<vifptr_t>(c.*mfp);
printf("%p\n", reinterpret_cast<void *>(baz));
printf("%p\n", reinterpret_cast<void *>(biz));
(c.*zup)(123);
(*baz)(1234, 321);
(*baz)(0x1234, 321);
(*biz)(0x4321, 432);
return 0;
}