class A
{
public:
A()
{
cout<<"ctor A\n";
}
virtual void func(int x)
{
cout<<"\nsj\n";
}
};
int _tmain(int argc, _TCHAR* argv[])
{
A objA;
int *vptr = (int *)*((int *)&objA);// address of the virtual table
typedef void (*fnptr)(int);
fnptr f;
f = (fnptr)*((int *)vptr+0);// address of func() within virtual table
f(9); // Calling func(). What is going wrong here ???
return 0;
}
When i call the function pointer, i get a "runtime check failure" (debug error) on VC.
What is it that i am doing wrong ?
The error states ->
" The value of ESP was not properly saved across a function call. This is
actually a result of calling a function with one calling convention with a function
pointer declared with a different calling convention".