Having trouble to call an event handler directly from my code. I found the same question 2 years ago here. original question
But the line
me_InsertCommentText(wxCo
The answer about using a named temporary variable is technically correct, but the important thing is that you really shouldn't be doing this in the first place. The handlers are only supposed to be called from wxWidgets and instead of calling some OnFoo(wxFooEvent&)
directly you should refactor your code to just call some new DoFoo()
from OnFoo()
and then call DoFoo()
from the rest of your code if you need it.
This becomes even simpler when using C++11 as you don't even need to have OnFoo()
at all in this case and could just write
whatever->Bind(wxEVT_FOO, [=](wxCommandEvent&) { DoFoo(); });
to avoid an extra function.