Address of member functions
-
Hi, Is it possible to obtain beginning & ending addresses of public member functions of C++ object, outside the object? If yes How? Thanks Yogesh
-
Hi, Is it possible to obtain beginning & ending addresses of public member functions of C++ object, outside the object? If yes How? Thanks Yogesh
If the class has no inheritance or just single inheritance, you can get its starting address:
class A
{
public:
int func() { return 1; }
};int (A::*ptr_to_method)() = A::func;
ptr_to_method
now holds the address of the method. But this address won't always be called if the method can be inlined (as the one above) so every call toA::func()
might not go through that address in memory. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- You cannot truly appreciate Dilbert unless you've read it in the original Klingon. -
If the class has no inheritance or just single inheritance, you can get its starting address:
class A
{
public:
int func() { return 1; }
};int (A::*ptr_to_method)() = A::func;
ptr_to_method
now holds the address of the method. But this address won't always be called if the method can be inlined (as the one above) so every call toA::func()
might not go through that address in memory. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- You cannot truly appreciate Dilbert unless you've read it in the original Klingon.As I understand, the function addresses obtained using this way are not the real addresses. They just provide an offset of a member function within an object. #include class A { public: int func() { return 1; } }; void main(){ A x; int (A::*ptr_to_method)() = A::func; getch(); } If for the above program you check inside Watch window of VC++ 6.0, the values of following variables ptr_to_method (&x)->func It shows different addresses. Now which one is the correct address of function "func"? Also I was not able to capture the value of "(&x)->func" inside program.
-
If the class has no inheritance or just single inheritance, you can get its starting address:
class A
{
public:
int func() { return 1; }
};int (A::*ptr_to_method)() = A::func;
ptr_to_method
now holds the address of the method. But this address won't always be called if the method can be inlined (as the one above) so every call toA::func()
might not go through that address in memory. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- You cannot truly appreciate Dilbert unless you've read it in the original Klingon.Also is there any way to find an address where the function ends?