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. Member function pointer

Member function pointer

Scheduled Pinned Locked Moved C / C++ / MFC
help
3 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.
  • K Offline
    K Offline
    kikocharana
    wrote on last edited by
    #1

    Hello , ive got the following member function pointer problem noting that all my search result on the net wasn't useful at all. class MyClass { Anotherclass MyObject; void Function1(); void FunctionNeededPointer(Float*,int,int); }; void MyClass::Function1() { //Here i need to pass a pointer of a function to the //following function belonging to MyObject //void Anotherclass::Function(void *aFunction,void // *callingObject=NULL) //so i tried this and didn't work void (MyClass::*pToFunction)(float*,int,int) = &MyClass::FunctionNeededPointer; MyObject.Function((void*)pToFunction); //oops error: cannot convert from void(__thiscall // Myclass::*)(float*,int,int) to void* //So had to make that function static and worked but //it ended up that every thing in MyClass was converted //to static which is not a nice solution at all //so i'm wondering if someone could help with this //problem }

    B 1 Reply Last reply
    0
    • K kikocharana

      Hello , ive got the following member function pointer problem noting that all my search result on the net wasn't useful at all. class MyClass { Anotherclass MyObject; void Function1(); void FunctionNeededPointer(Float*,int,int); }; void MyClass::Function1() { //Here i need to pass a pointer of a function to the //following function belonging to MyObject //void Anotherclass::Function(void *aFunction,void // *callingObject=NULL) //so i tried this and didn't work void (MyClass::*pToFunction)(float*,int,int) = &MyClass::FunctionNeededPointer; MyObject.Function((void*)pToFunction); //oops error: cannot convert from void(__thiscall // Myclass::*)(float*,int,int) to void* //So had to make that function static and worked but //it ended up that every thing in MyClass was converted //to static which is not a nice solution at all //so i'm wondering if someone could help with this //problem }

      B Offline
      B Offline
      Brian Shifrin
      wrote on last edited by
      #2

      With classes you have two options: 1) make function static, so that all objects of the type MyClass reference the same static function. In this case you can use MyClass::FunctionNeededPointer 2) Function you are trying to pass is not static. To pass function pointer you should use something like "this->FunctionNeededPointer", since function obviously has very little meaning outside of class scope... 3) Here is how you can define function type typedef void (MYFUNCTION)(float*,int,int); void Function(MYFUNCTION *p); { Function(&this->FunctionNeededPointer); } Brian

      K 1 Reply Last reply
      0
      • B Brian Shifrin

        With classes you have two options: 1) make function static, so that all objects of the type MyClass reference the same static function. In this case you can use MyClass::FunctionNeededPointer 2) Function you are trying to pass is not static. To pass function pointer you should use something like "this->FunctionNeededPointer", since function obviously has very little meaning outside of class scope... 3) Here is how you can define function type typedef void (MYFUNCTION)(float*,int,int); void Function(MYFUNCTION *p); { Function(&this->FunctionNeededPointer); } Brian

        K Offline
        K Offline
        kikocharana
        wrote on last edited by
        #3

        Thanks for your reply, but i forgot to mention something that i haven't got any control on the function Function(void *aFunction , void *callingObject=null) as it came with a header file of a library and i've got to use it as is, besides when i try to use &this->FuctionNeededPointer it gives the following error '&' : illegal operation on bound member function expression

        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