c++ - Calling member function of one class from another -


i have problem big piece of code have event handling objects. in event handling class trying call function of class through pointer having same error code have have implemented check logic using call there. wrong doing here?

#include <iostream> using namespace std; class functionpointer; class usefp { public:     usefp(void){}     ~usefp(void){}      void modified(int m,int n);     void (functionpointer::*update)(int,int);  };  void usefp::modified(int m,int n)     {             //(this->*update)(m,n);// call fp if uncomment it gives error.     }  class functionpointer {     int a,b;     usefp * obj; public:     functionpointer(void);      ~functionpointer(void);      void updatedata(int m, int n)     {         = m;         b = n;         cout<<"\n\nupdated: "<<a<<", b "<<b<<endl;     }      void input()     {         int m, n;         cout<<"\nenter new data: ";         cin>>m>>n;         obj->modified(m,n);     }     };  void main() {     functionpointer obj;     obj.input(); } 

errors after uncommenting function call

1>------ build started: project: functionpointer, configuration: debug win32 ------ 1>compiling... 1>main.cpp 1>c:\users\volmo\desktop\functionpointer\functionpointer\functionpointer.h(14) : error c2440: 'newline' : cannot convert 'usefp *const ' 'functionpointer *const ' 1>        types pointed unrelated; conversion requires reinterpret_cast, c-style cast or function-style cast 1>c:\users\volmo\desktop\functionpointer\functionpointer\functionpointer.h(14) : error c2647: '->*' : cannot dereference 'void (__thiscall functionpointer::* )(int,int)' on 'usefp *const ' 1>generating code... 1>compiling... 1>functionpointer.cpp 1>c:\users\volmo\desktop\functionpointer\functionpointer\functionpointer.h(14) : error c2440: 'newline' : cannot convert 'usefp *const ' 'functionpointer *const ' 1>        types pointed unrelated; conversion requires reinterpret_cast, c-style cast or function-style cast 1>c:\users\volmo\desktop\functionpointer\functionpointer\functionpointer.h(14) : error c2647: '->*' : cannot dereference 'void (__thiscall functionpointer::* )(int,int)' on 'usefp *const ' 1>generating code... 1>build log saved @ "file://c:\users\volmo\desktop\functionpointer\functionpointer\debug\buildlog.htm" 1>functionpointer - 4 error(s), 0 warning(s)     ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

update typed "pointer member function of class functionpointer. means requires functionpointer instance on left of ->*. you're trying dereference this of type usefp. hence error.

you need instance of functionpointer invoke update on it. don't know intended semantics is, 1 way obtain 1 add parameter modified:

void usefp::modified(functionpointer &fp, int m,int n)     {             (fp.*update)(m,n);     } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -