Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Address of member functions

Address of member functions

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yogesh Kshatriya
    wrote on last edited by
    #1

    Hi, Is it possible to obtain beginning & ending addresses of public member functions of C++ object, outside the object? If yes How? Thanks Yogesh

    M 1 Reply Last reply
    0
    • Y Yogesh Kshatriya

      Hi, Is it possible to obtain beginning & ending addresses of public member functions of C++ object, outside the object? If yes How? Thanks Yogesh

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      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 to A::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.

      Y 2 Replies Last reply
      0
      • M Michael Dunn

        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 to A::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.

        Y Offline
        Y Offline
        Yogesh Kshatriya
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M Michael Dunn

          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 to A::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.

          Y Offline
          Y Offline
          Yogesh Kshatriya
          wrote on last edited by
          #4

          Also is there any way to find an address where the function ends?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups