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. function pointer ,,,easy but not simple

function pointer ,,,easy but not simple

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
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.
  • V Offline
    V Offline
    vtalau
    wrote on last edited by
    #1

    I have a problem with using function poiter. My program has two parts: part 1: mydll.dll typedef BOOL (*SpeakFunc)(const CString s); #define DLL_EXPORT __declspec(dllexport) BOOL DLL_EXPORT Init(HWND hwnd,SpeakFunc func) { ... } part 2: adding the mydll.lib of the part 1 into the project of the part 2 in the test.cpp file of the "Test" class typedef BOOL (*SpeakFunc)(const CString str); extern BOOL Init(HWND hwnd,SpeakFunc func); BOOL CTest::Speak(const CString) { ... } void CTest::TestMethod() { ... Init (NULL,&CTest::Speak) ; // the compiler notices an error here ... } The error message like below: "error C2440: 'initializing' : cannot convert from 'int (__thiscall CTest::*)(const class CString)' to 'int (__cdecl *)(const class CString)' There is no context in which this conversion is possible" please help me...Thanks a lot.

    S M 2 Replies Last reply
    0
    • V vtalau

      I have a problem with using function poiter. My program has two parts: part 1: mydll.dll typedef BOOL (*SpeakFunc)(const CString s); #define DLL_EXPORT __declspec(dllexport) BOOL DLL_EXPORT Init(HWND hwnd,SpeakFunc func) { ... } part 2: adding the mydll.lib of the part 1 into the project of the part 2 in the test.cpp file of the "Test" class typedef BOOL (*SpeakFunc)(const CString str); extern BOOL Init(HWND hwnd,SpeakFunc func); BOOL CTest::Speak(const CString) { ... } void CTest::TestMethod() { ... Init (NULL,&CTest::Speak) ; // the compiler notices an error here ... } The error message like below: "error C2440: 'initializing' : cannot convert from 'int (__thiscall CTest::*)(const class CString)' to 'int (__cdecl *)(const class CString)' There is no context in which this conversion is possible" please help me...Thanks a lot.

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      In "part 1" you declare SpeakFunc as a global function but in "part 2" you attempt to pass a pointer to a member function. Steve

      1 Reply Last reply
      0
      • V vtalau

        I have a problem with using function poiter. My program has two parts: part 1: mydll.dll typedef BOOL (*SpeakFunc)(const CString s); #define DLL_EXPORT __declspec(dllexport) BOOL DLL_EXPORT Init(HWND hwnd,SpeakFunc func) { ... } part 2: adding the mydll.lib of the part 1 into the project of the part 2 in the test.cpp file of the "Test" class typedef BOOL (*SpeakFunc)(const CString str); extern BOOL Init(HWND hwnd,SpeakFunc func); BOOL CTest::Speak(const CString) { ... } void CTest::TestMethod() { ... Init (NULL,&CTest::Speak) ; // the compiler notices an error here ... } The error message like below: "error C2440: 'initializing' : cannot convert from 'int (__thiscall CTest::*)(const class CString)' to 'int (__cdecl *)(const class CString)' There is no context in which this conversion is possible" please help me...Thanks a lot.

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

        See the FAQ 6.5 How do I declare and use a pointer to a class member function?[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        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