Click here to Skip to main content
15,912,578 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: catching the memory using without initializing Pin
shahin namini17-Oct-07 10:16
shahin namini17-Oct-07 10:16 
AnswerRe: catching the memory using without initializing Pin
Chris Losinger17-Oct-07 10:17
professionalChris Losinger17-Oct-07 10:17 
GeneralRe: catching the memory using without initializing Pin
shahin namini17-Oct-07 10:37
shahin namini17-Oct-07 10:37 
QuestionRe: catching the memory using without initializing Pin
David Crow17-Oct-07 10:44
David Crow17-Oct-07 10:44 
GeneralRe: catching the memory using without initializing Pin
Chris Losinger17-Oct-07 10:59
professionalChris Losinger17-Oct-07 10:59 
AnswerRe: catching the memory using without initializing Pin
David Crow17-Oct-07 10:20
David Crow17-Oct-07 10:20 
GeneralRe: catching the memory using without initializing Pin
shahin namini17-Oct-07 10:40
shahin namini17-Oct-07 10:40 
Questioncallbacks in C++: member function pointers / objects Pin
elmendavies17-Oct-07 8:01
elmendavies17-Oct-07 8:01 
Hello,
If I need to use a function in a C library that I can't modify, let's say:

extern "C"
{
void register_callback(void (*callback) (void));
}

... if I also have a class like this:

class MyClass
{
int m_counter;
public:
MyClass() : m_counter(0) {}
void OnEvent()
{
m_counter++;
}
}

Is there any solucion to use MyClass::OnEvent with the funcion register_callback()? In other words, I would like to do something like this (Of course this doesn't work):

int main (void)
{
MyClass my;
register_callback(&(my.MyClass::OnEvent))
}


It's very easy to make MyClass a singleton and define MyClass::OnEvent() as 'static' or use a singleton inside MyClass, which is enough in almost all the cases but I don't want to modify MyClass at all.

I've tried this one:

int main (void)
{
register_callback(sigc::mem_fun(*this,&MyClass::OnEvent));
...
}

That doesn't work. One of the problems is that sig::mem_fun() return an object created in the stack and the parameter for register_callback must be a 'const' one.

Thank you in advance,
Miguel
AnswerRe: callbacks in C++: member function pointers / objects Pin
Jim Crafton17-Oct-07 8:22
Jim Crafton17-Oct-07 8:22 
GeneralRe: callbacks in C++: member function pointers / objects Pin
elmendavies18-Oct-07 0:02
elmendavies18-Oct-07 0:02 
AnswerRe: callbacks in C++: member function pointers / objects Pin
Chris Losinger17-Oct-07 8:37
professionalChris Losinger17-Oct-07 8:37 
GeneralRe: callbacks in C++: member function pointers / objects Pin
elmendavies18-Oct-07 0:12
elmendavies18-Oct-07 0:12 
AnswerRe: callbacks in C++: member function pointers / objects Pin
Stephen Hewitt17-Oct-07 16:44
Stephen Hewitt17-Oct-07 16:44 
GeneralRe: callbacks in C++: member function pointers / objects Pin
elmendavies18-Oct-07 0:17
elmendavies18-Oct-07 0:17 
GeneralRe: callbacks in C++: member function pointers / objects Pin
Stephen Hewitt18-Oct-07 14:26
Stephen Hewitt18-Oct-07 14:26 
Questionerror in splitt, Help Pin
satw1417-Oct-07 6:32
satw1417-Oct-07 6:32 
QuestionRe: error in splitt, Help Pin
David Crow17-Oct-07 6:39
David Crow17-Oct-07 6:39 
AnswerRe: error in splitt, Help [modified] Pin
satw1417-Oct-07 12:16
satw1417-Oct-07 12:16 
QuestionRe: error in splitt, Help Pin
David Crow17-Oct-07 17:50
David Crow17-Oct-07 17:50 
AnswerRe: error in splitt, Help Pin
James R. Twine17-Oct-07 7:04
James R. Twine17-Oct-07 7:04 
QuestionHow to Convert a Float to a string Pin
saravana00117-Oct-07 5:37
saravana00117-Oct-07 5:37 
AnswerRe: How to Convert a Float to a string Pin
Nelek17-Oct-07 5:44
protectorNelek17-Oct-07 5:44 
AnswerRe: How to Convert a Float to a string Pin
Chris Losinger17-Oct-07 5:46
professionalChris Losinger17-Oct-07 5:46 
AnswerRe: How to Convert a Float to a string Pin
VonHagNDaz17-Oct-07 5:59
VonHagNDaz17-Oct-07 5:59 
GeneralRe: How to Convert a Float to a string Pin
James R. Twine17-Oct-07 6:57
James R. Twine17-Oct-07 6:57 

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.