with the visual c++ x86 compiler, the show function can be called, but the property a of the class Demo will be a random number in memory, I try to call in the way of comment, But it's useless, can someone help me how to call this function in a right way
#include <iostream>
using namespace std;
class Demo {
public:
int a;
Demo(int a) :a(a) {};
virtual void show();
};
void Demo::show() {
cout << "a: " << a << endl;
}
int main() {
//typedef void (*func)(Demo * stu);
typedef void (*func)();
Demo d(100);
func f = (func)*((int*)*(int*)(&d));
//f(&stu);
f();
return 0;
}