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 on classfunctions

function pointer on classfunctions

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 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.
  • T Offline
    T Offline
    tbrake
    wrote on last edited by
    #1

    H@llo I have a class with some memberfunctions and like to refer to these by unsing functionpointers. all my tries ends up in errors some sample here: // myCom.h class myCom { public: int send(int,char*); int read(int,unsigned int,BYTE*); }; // action.h class myCom; typedef int (*cdout)(int ,char* ); typedef int (*cdread)(int ,unsigned int ,BYTE* ); class action { myCom* mCom; ... }; // action.cpp ... mCom = new myCom; ... cdout test = mCom->send; // error C2440: 'initializing' : cannot convert from '' to 'int (__cdecl *)(int,char *)' or cdout test; test = mCom->send; // error C2440: '=' : cannot convert from 'int (__thiscall CINTERFACE::*)(int,char *)' to 'int (__cdecl *)(int,char *)' ... :confused: Anyone any idea?? THX

    T B 2 Replies Last reply
    0
    • T tbrake

      H@llo I have a class with some memberfunctions and like to refer to these by unsing functionpointers. all my tries ends up in errors some sample here: // myCom.h class myCom { public: int send(int,char*); int read(int,unsigned int,BYTE*); }; // action.h class myCom; typedef int (*cdout)(int ,char* ); typedef int (*cdread)(int ,unsigned int ,BYTE* ); class action { myCom* mCom; ... }; // action.cpp ... mCom = new myCom; ... cdout test = mCom->send; // error C2440: 'initializing' : cannot convert from '' to 'int (__cdecl *)(int,char *)' or cdout test; test = mCom->send; // error C2440: '=' : cannot convert from 'int (__thiscall CINTERFACE::*)(int,char *)' to 'int (__cdecl *)(int,char *)' ... :confused: Anyone any idea?? THX

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      you have typedef int (*cdout)(int ,char* ); and int send(int,char*); but send is a member function... its synopsis is not what you wrote. it gets an implicit parameter (this). send() actually has 3 parameters. if you want to use it, you must declare it as a static function. but if it uses data members of its class, it won't see them anymore. so you'll have to pass a new parameter explicitely to your send() function to allow it accessing the members. You'll also have to change the cdout declaration... cheers,


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      T 1 Reply Last reply
      0
      • T toxcct

        you have typedef int (*cdout)(int ,char* ); and int send(int,char*); but send is a member function... its synopsis is not what you wrote. it gets an implicit parameter (this). send() actually has 3 parameters. if you want to use it, you must declare it as a static function. but if it uses data members of its class, it won't see them anymore. so you'll have to pass a new parameter explicitely to your send() function to allow it accessing the members. You'll also have to change the cdout declaration... cheers,


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        T Offline
        T Offline
        tbrake
        wrote on last edited by
        #3

        Hallo OK - got it so far. :) But at least i like to send this functionpointer to a created dll. So ifsend() is static i have to change to much code. Changeing the typedef restricts the needed parsing possibility for my dll. :doh: I'm sorry, but i'm not very good in c programming. Is there any other fast possibility to call a dll function that communicating with class member functions? :confused: THX

        T 1 Reply Last reply
        0
        • T tbrake

          Hallo OK - got it so far. :) But at least i like to send this functionpointer to a created dll. So ifsend() is static i have to change to much code. Changeing the typedef restricts the needed parsing possibility for my dll. :doh: I'm sorry, but i'm not very good in c programming. Is there any other fast possibility to call a dll function that communicating with class member functions? :confused: THX

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          just put send not a member function... (say it is global... or at least, from within a namespace of your own)


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          1 Reply Last reply
          0
          • T tbrake

            H@llo I have a class with some memberfunctions and like to refer to these by unsing functionpointers. all my tries ends up in errors some sample here: // myCom.h class myCom { public: int send(int,char*); int read(int,unsigned int,BYTE*); }; // action.h class myCom; typedef int (*cdout)(int ,char* ); typedef int (*cdread)(int ,unsigned int ,BYTE* ); class action { myCom* mCom; ... }; // action.cpp ... mCom = new myCom; ... cdout test = mCom->send; // error C2440: 'initializing' : cannot convert from '' to 'int (__cdecl *)(int,char *)' or cdout test; test = mCom->send; // error C2440: '=' : cannot convert from 'int (__thiscall CINTERFACE::*)(int,char *)' to 'int (__cdecl *)(int,char *)' ... :confused: Anyone any idea?? THX

            B Offline
            B Offline
            Behzad Ebrahimi
            wrote on last edited by
            #5

            See Class function callback[^]

            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