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. Managed C++/CLI
  4. How to cast a pointer to a member function into a void*?

How to cast a pointer to a member function into a void*?

Scheduled Pinned Locked Moved Managed C++/CLI
helptutorialquestion
3 Posts 3 Posters 2 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.
  • C Offline
    C Offline
    Charles Liu
    wrote on last edited by
    #1

    I got the code as follows: class A{ int f(); //f defined elsewhere } void main() { void* p; p = A::f; //it gives a compiler error //how to cast f into p? //My friend did that in asm, however i want an easier way. } Thanks in advance

    N J 2 Replies Last reply
    0
    • C Charles Liu

      I got the code as follows: class A{ int f(); //f defined elsewhere } void main() { void* p; p = A::f; //it gives a compiler error //how to cast f into p? //My friend did that in asm, however i want an easier way. } Thanks in advance

      N Offline
      N Offline
      Natty Gur
      wrote on last edited by
      #2

      System::Runtime::InteropServices::Marshal::StructToPtr(ManagedObject,PointerToVoid,true)

      1 Reply Last reply
      0
      • C Charles Liu

        I got the code as follows: class A{ int f(); //f defined elsewhere } void main() { void* p; p = A::f; //it gives a compiler error //how to cast f into p? //My friend did that in asm, however i want an easier way. } Thanks in advance

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        void* p = (void*)(A::f); C++ compilers are very strict, they want to make absolutly sure you know what you are doing (this is a good thing). If you need to do this you are probubly doing some thing wrong. I recommend that you read up on vetual base classes. Trust in the code Luke. Yea right!

        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