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. Fucntion pointer question!

Fucntion pointer question!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++tutorial
3 Posts 3 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.
  • G Offline
    G Offline
    G Richard
    wrote on last edited by
    #1

    i declare a function pointer like this: void (*PTestFunc)(CString& str); and two classes: class CTest { ... void Test() { m_pTestFunc(CString("fdsaf")); } void SetFuncPointer(void* pointer) { m_pTestFunc = pointer; } PTestFunc m_pTestFunc; ... } class CMyClass { ... CString m_strCaption; void MyTest(CString& str); void Init(CTest& test); ... } CMyClass::MyTest(CString& str) { m_strCaption = str; } void CMyClass::Init(CTest& test) { test.SetFuncPointer((void*)MyTest); //error c2440 } ////////////////////////////// if i add "static" before MyTest, it is right; but u see i need this pointer in my class, i can't set MyTest static. so how to solve this problem? does c++ define the class member function pointer? :confused: c++ : my dream

    M T 2 Replies Last reply
    0
    • G G Richard

      i declare a function pointer like this: void (*PTestFunc)(CString& str); and two classes: class CTest { ... void Test() { m_pTestFunc(CString("fdsaf")); } void SetFuncPointer(void* pointer) { m_pTestFunc = pointer; } PTestFunc m_pTestFunc; ... } class CMyClass { ... CString m_strCaption; void MyTest(CString& str); void Init(CTest& test); ... } CMyClass::MyTest(CString& str) { m_strCaption = str; } void CMyClass::Init(CTest& test) { test.SetFuncPointer((void*)MyTest); //error c2440 } ////////////////////////////// if i add "static" before MyTest, it is right; but u see i need this pointer in my class, i can't set MyTest static. so how to solve this problem? does c++ define the class member function pointer? :confused: c++ : my dream

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

      Non-static methods have 'this' as the first parameter. I just added a FAQ on this to the VC Forum FAQ, so check that out. :) --Mike-- It's hammer time! My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan and Jamie Salé.

      1 Reply Last reply
      0
      • G G Richard

        i declare a function pointer like this: void (*PTestFunc)(CString& str); and two classes: class CTest { ... void Test() { m_pTestFunc(CString("fdsaf")); } void SetFuncPointer(void* pointer) { m_pTestFunc = pointer; } PTestFunc m_pTestFunc; ... } class CMyClass { ... CString m_strCaption; void MyTest(CString& str); void Init(CTest& test); ... } CMyClass::MyTest(CString& str) { m_strCaption = str; } void CMyClass::Init(CTest& test) { test.SetFuncPointer((void*)MyTest); //error c2440 } ////////////////////////////// if i add "static" before MyTest, it is right; but u see i need this pointer in my class, i can't set MyTest static. so how to solve this problem? does c++ define the class member function pointer? :confused: c++ : my dream

        T Offline
        T Offline
        Todd Smith
        wrote on last edited by
        #3

        Not sure if this will solve your problem http://www.codetools.com/script/comments/forums.asp?forumid=1647&app=50&fr=251#xx142181xx Todd Smith CPUA 0x007 ... shaken not stirred

        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