Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Class member function as call back Pin
CPallini14-Mar-19 4:16
mveCPallini14-Mar-19 4:16 
AnswerRe: Class member function as call back Pin
Richard MacCutchan14-Mar-19 5:00
mveRichard MacCutchan14-Mar-19 5:00 
GeneralRe: Class member function as call back Pin
NoviceEx14-Mar-19 21:29
NoviceEx14-Mar-19 21:29 
GeneralRe: Class member function as call back Pin
CPallini14-Mar-19 22:44
mveCPallini14-Mar-19 22:44 
GeneralRe: Class member function as call back Pin
Richard MacCutchan14-Mar-19 23:02
mveRichard MacCutchan14-Mar-19 23:02 
GeneralRe: Class member function as call back Pin
CPallini15-Mar-19 1:49
mveCPallini15-Mar-19 1:49 
GeneralRe: Class member function as call back Pin
Richard MacCutchan15-Mar-19 2:57
mveRichard MacCutchan15-Mar-19 2:57 
AnswerRe: Class member function as call back Pin
Stefan_Lang19-Mar-19 4:07
Stefan_Lang19-Mar-19 4:07 
boost::bind returns a function object, not a C function. It may behave like a function pointer, but these types are different, and the compiler won't be able to match the function argument list with a function object as the second argument.

The problem you describe cannot be solved with the limitations you've set. Clearly, part of the limitations are of your own making and need to be revised. To understand that, you just need to think about the flow of control:
1. from your code you set up a callback mechanism that is supposed to call your callback function
2. then you call a function outside of your code
3. At some point this outside function calls your callback function, passing along some data
4. Your callback function is called. the only data it has are the function arguments it got passed from it's calling function. At this point it is entirely out of context from the rest of your application and doesn't know about any of your B objects that you may have created. If the calling function doesn't know about Bs, then the callback function cannot know about them either.

It is impossible to process anything dependend on some B member variables in the callback function, unless you pass these variables all the way from step 1 through step 4! Unfortunately the code in step 3 is outside your control - therefore this is impossible. Or it wouldbe impossible if you insist on passing along a reference to some B object: the caller doesn't know about that class!

There are only two solutions that may work:
1. the library you are using lets you pass along additional data to the callback setup which then will be passed to the callback invocation. If so, you could just pass along the values of var1 and var2.
2. If the above isn't possible, the only alternative I see is to use global variables to store the state of B or just its member variables.

Of course. the premise that your callback absolutely needs to know your B object may have been wrong! Time to think about how you intended to use this callback mechanism!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

QuestionWin32++ Dialog Pin
Member 1372187514-Mar-19 1:32
Member 1372187514-Mar-19 1:32 
AnswerRe: Win32++ Dialog Pin
Richard MacCutchan14-Mar-19 1:58
mveRichard MacCutchan14-Mar-19 1:58 
GeneralRe: Win32++ Dialog Pin
CPallini14-Mar-19 2:30
mveCPallini14-Mar-19 2:30 
GeneralRe: Win32++ Dialog Pin
Richard MacCutchan14-Mar-19 2:35
mveRichard MacCutchan14-Mar-19 2:35 
AnswerRe: Win32++ Dialog Pin
leon de boer14-Mar-19 14:34
leon de boer14-Mar-19 14:34 
QuestionGet file size Pin
_Flaviu14-Mar-19 0:31
_Flaviu14-Mar-19 0:31 
AnswerRe: Get file size Pin
CPallini14-Mar-19 1:09
mveCPallini14-Mar-19 1:09 
GeneralRe: Get file size Pin
_Flaviu14-Mar-19 1:20
_Flaviu14-Mar-19 1:20 
GeneralRe: Get file size Pin
CPallini14-Mar-19 1:24
mveCPallini14-Mar-19 1:24 
QuestionGet system image list not working in some cases Pin
_Flaviu13-Mar-19 7:07
_Flaviu13-Mar-19 7:07 
SuggestionRe: Get system image list not working in some cases Pin
Richard MacCutchan13-Mar-19 22:18
mveRichard MacCutchan13-Mar-19 22:18 
GeneralRe: Get system image list not working in some cases Pin
_Flaviu14-Mar-19 0:16
_Flaviu14-Mar-19 0:16 
QuestionWrite in registry Pin
_Flaviu13-Mar-19 0:04
_Flaviu13-Mar-19 0:04 
AnswerRe: Write in registry Pin
Richard Deeming13-Mar-19 1:41
mveRichard Deeming13-Mar-19 1:41 
GeneralRe: Write in registry Pin
_Flaviu13-Mar-19 3:53
_Flaviu13-Mar-19 3:53 
Questioninline question Pin
Rw23712-Mar-19 12:52
Rw23712-Mar-19 12:52 
AnswerRe: inline question Pin
CPallini12-Mar-19 21:48
mveCPallini12-Mar-19 21:48 

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.