2)Assign the address of the function in A to the function pointer
You can't.
Each function has a prolog and epilog like __thiscall and __stdcall, __cdecl, __fastcall etc. If you declare the function inside of the class no matter if it is a function pointer or not, it seems that is uses __thiscall. You cannot cast this away because it is saying you need an object of some type to call this function with.
The functions in A are not private, the instance of A in B is protected, therefore it doesn't matter if A's functions are public or not...you cannot get to the instance of A in B from outside of B. I do not want to return the instance of A in B - essentially I need to limit certain functions. But there is a better way and the inline method is where I'm headed as well. Also will make vital functions protected so that even if you have a copy of A, you still cannot call those functions unless you are in A or a derivation of A.
The prolog/epilog for __stdcall would be something like this (I think)
Code:
@MyFunc:
push ebp
mov esp,ebp
...
pop ebp
Read the compiler docs as each one is explained including who is responsible for cleaning up the stack.
The reason I could do this in assembly is because most of C++ is compiler-side rules, that is they are only in effect inside of the compiler. Once the object code has been written, I can still gain access to anything I want from pure asm code. However, this is not a good practice and I won't get into manually editing my C++ code.
The __pascal modifier means that parameters are pushed from right to left and the __cdecl means they are pushed from right to left (or vice versa I forget).
So if you have a function like so in 32-bit code:
unsigned int Subtract(unsigned int v1,unsigned int v2)
To call this:
Code:
push [v2]
push [v1]
call Subtract
Subtract:
push ebp
mov ebp,esp
mov eax,[ebp+12]
sub eax,[ebp+8]
pop ebp
Which is far different from:
Code:
push [v1]
push [v2]
call Subtract
Subtract:
push ebp
mov ebp,esp
mov eax,[ebp+12]
sub eax,[ebp+8]
pop ebp
The two will yield very different results. And this is of course barring the fact that name mangling will occur with C++, unless you explicity tell it not to mangle them.