Click here to Skip to main content
15,900,563 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionAbout virtual function Pin
EhtishamArshad28-Jan-13 19:40
EhtishamArshad28-Jan-13 19:40 
AnswerRe: About virtual function Pin
Jibesh28-Jan-13 19:51
professionalJibesh28-Jan-13 19:51 
GeneralRe: About virtual function Pin
EhtishamArshad28-Jan-13 22:32
EhtishamArshad28-Jan-13 22:32 
AnswerRe: About virtual function Pin
Richard MacCutchan28-Jan-13 22:48
mveRichard MacCutchan28-Jan-13 22:48 
Questionwhere can download comment macro? Pin
yu-jian28-Jan-13 15:36
yu-jian28-Jan-13 15:36 
AnswerRe: where can download comment macro? Pin
Jibesh28-Jan-13 19:48
professionalJibesh28-Jan-13 19:48 
QuestionFilter the EN_KILLFOCUS message from CIPAddressCtrl Pin
zhangyoung28-Jan-13 14:53
zhangyoung28-Jan-13 14:53 
AnswerRe: Filter the EN_KILLFOCUS message from CIPAddressCtrl Pin
Code-o-mat28-Jan-13 22:27
Code-o-mat28-Jan-13 22:27 
GeneralRe: Filter the EN_KILLFOCUS message from CIPAddressCtrl Pin
zhangyoung29-Jan-13 3:04
zhangyoung29-Jan-13 3:04 
GeneralRe: Filter the EN_KILLFOCUS message from CIPAddressCtrl Pin
Code-o-mat29-Jan-13 3:13
Code-o-mat29-Jan-13 3:13 
QuestionHow to create an uncompressed avi file from a matrix of data? Pin
Kiran Satish27-Jan-13 16:40
Kiran Satish27-Jan-13 16:40 
QuestionRe: How to create an uncompressed avi file from a matrix of data? Pin
CPallini27-Jan-13 22:38
mveCPallini27-Jan-13 22:38 
AnswerRe: How to create an uncompressed avi file from a matrix of data? Pin
Kiran Satish28-Jan-13 4:42
Kiran Satish28-Jan-13 4:42 
AnswerRe: How to create an uncompressed avi file from a matrix of data? Pin
Chris Losinger28-Jan-13 5:10
professionalChris Losinger28-Jan-13 5:10 
AnswerRe: How to create an uncompressed avi file from a matrix of data? Pin
Vaclav_28-Jan-13 9:50
Vaclav_28-Jan-13 9:50 
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 

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.