Click here to Skip to main content
15,885,366 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to create an uncompressed avi file from a matrix of data? Pin
Shaheed Legion26-Feb-13 5:51
Shaheed Legion26-Feb-13 5:51 
QuestionWaveInOpen() returns error code 11 Pin
AmbiguousName26-Jan-13 3:14
AmbiguousName26-Jan-13 3:14 
AnswerRe: WaveInOpen() returns error code 11 Pin
Richard MacCutchan26-Jan-13 3:28
mveRichard MacCutchan26-Jan-13 3:28 
QuestionStuck with function pointers in C and C++ Pin
Simon Langdon25-Jan-13 0:38
Simon Langdon25-Jan-13 0:38 
AnswerRe: Stuck with function pointers in C and C++ Pin
CPallini25-Jan-13 0:59
mveCPallini25-Jan-13 0:59 
AnswerRe: Stuck with function pointers in C and C++ Pin
Freak3025-Jan-13 1:08
Freak3025-Jan-13 1:08 
GeneralRe: Stuck with function pointers in C and C++ Pin
Simon Langdon25-Jan-13 1:41
Simon Langdon25-Jan-13 1:41 
GeneralRe: Stuck with function pointers in C and C++ Pin
Stefan_Lang29-Jan-13 0:02
Stefan_Lang29-Jan-13 0:02 
If modifying your global function is out of the question, then you can only pass it either a global function or a static class function. There is no other way. As CPallini remarked, the type of a pointer to a nonstatic member function is incompatible with your function pointer type definition.

What's more: a pointer to a nonstatic member function requires more memory to store than a simple function pointer, so casting is out of the question, too!

The question is: what is your goal? You're converting code, so why can't you change that global function?

If you really can't, the only solution I can think of would be a wrapper function that calls your member function indirectly:

C++
namespace wrapper {
   class theClass* instance; // global variable required!
   int theClassWrapper(int arg) {
      int ret = 0;
      if (instance != nullptr)
         ret = instance->theFunction(arg);
      return ret;
   }
};
int theClass::anotherFunction() {
   wrapper::instance = this;
   return globFunction(&wrapper::theClassWrapper, true);
}

I've put the required additional global variable and global function inside a namespace to minimize global namespace polution and risk of conflicts, but you cannot avoid these additional globals if you cannot modify your existing global function.
GeneralRe: Stuck with function pointers in C and C++ Pin
Simon Langdon29-Jan-13 0:38
Simon Langdon29-Jan-13 0:38 
GeneralRe: Stuck with function pointers in C and C++ Pin
Stefan_Lang29-Jan-13 4:31
Stefan_Lang29-Jan-13 4:31 
GeneralRe: Stuck with function pointers in C and C++ Pin
CPallini25-Jan-13 2:04
mveCPallini25-Jan-13 2:04 
GeneralRe: Stuck with function pointers in C and C++ Pin
Freak3027-Jan-13 23:30
Freak3027-Jan-13 23:30 
AnswerRe: Stuck with function pointers in C and C++ Pin
Stephen Hewitt27-Jan-13 4:40
Stephen Hewitt27-Jan-13 4:40 
QuestionUSB Device Path Handle Problem Pin
002comp24-Jan-13 21:21
002comp24-Jan-13 21:21 
AnswerRe: USB Device Path Handle Problem Pin
Vaclav_28-Jan-13 10:08
Vaclav_28-Jan-13 10:08 
QuestionHow to create a button on the right of the screen in mfc.? Pin
mbatra3124-Jan-13 19:53
mbatra3124-Jan-13 19:53 
AnswerRe: How to create a button on the right of the screen in mfc.? Pin
Richard MacCutchan24-Jan-13 22:47
mveRichard MacCutchan24-Jan-13 22:47 
GeneralRe: How to create a button on the right of the screen in mfc.? Pin
mbatra3127-Jan-13 19:39
mbatra3127-Jan-13 19:39 
GeneralRe: How to create a button on the right of the screen in mfc.? Pin
Richard MacCutchan27-Jan-13 22:36
mveRichard MacCutchan27-Jan-13 22:36 
GeneralRe: How to create a button on the right of the screen in mfc.? Pin
mbatra3128-Jan-13 0:07
mbatra3128-Jan-13 0:07 
AnswerRe: How to create a button on the right of the screen in mfc.? Pin
Iain Clarke, Warrior Programmer24-Jan-13 23:13
Iain Clarke, Warrior Programmer24-Jan-13 23:13 
GeneralRe: How to create a button on the right of the screen in mfc.? Pin
mbatra3127-Jan-13 20:11
mbatra3127-Jan-13 20:11 
AnswerRe: How to create a button on the right of the screen in mfc.? Pin
Albert Holguin25-Jan-13 7:47
professionalAlbert Holguin25-Jan-13 7:47 
QuestionCall CListCtrl::GetItemCount() in work thread proble. Pin
yu-jian24-Jan-13 17:41
yu-jian24-Jan-13 17:41 
AnswerRe: Call CListCtrl::GetItemCount() in work thread proble. Pin
«_Superman_»24-Jan-13 18:03
professional«_Superman_»24-Jan-13 18:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.