Home » Community » Newbie corner » Callback and Thisback Function call parameters
Callback and Thisback Function call parameters [message #43429] |
Tue, 29 July 2014 11:50  |
NilaT
Messages: 70 Registered: November 2011 Location: Austria
|
Member |
|
|
Hi everybody, I've got a new question for you, which is driving me nuts.
Callbacks and Thisbacks are quite difficult for beginners, but I think I got them... almost 
One thing is still unclear to me.
How can I add Parameters to a Function which is called, when a callback occurs?
For example:
Somewhere I got this:
Callback2<Point, Point> WhenProductChanging;
and then I got this, somewhere
...
WhenProductChanging(p1, p2);
...
And somewhere else I got this:
xxx.WhenProductChanging = THISBACK(OnProductChanging);
And finally, I got the function itself:
void yyy::OnProductChanging(Point firstP, Point secondP)
{ /* do something */
}
Now, what I want is to add another parameter to my "OnProductChanging" Method, like for example:
void yyy::OnProductChanging(Point firstP, Point secondP, int newParameter)
{ /* do something */
}
So I thought I have to change the THISBACK to THISBACK1 and pass the parameter after the Methodname, like this:
xxx.WhenProductChanging = THISBACK1(OnProductChanging, 1);
But this doesn't work, because it seems that all necessary parameters come from the callback. How can I pass another parameter, which is defined somewhere else and not known in the "callback-calling" function?
Thanks in advance!
[Updated on: Tue, 29 July 2014 11:51] Report message to a moderator
|
|
|
|
Re: Callback and Thisback Function call parameters [message #43431 is a reply to message #43429] |
Tue, 29 July 2014 13:04   |
NilaT
Messages: 70 Registered: November 2011 Location: Austria
|
Member |
|
|
The problem is, at the Callback definition, I only have 2 Parameters.
The third is used at another place and is not known at the point of definition. (int was just an example, in real it's a pointer to an own class)
So, I have to add the third parameter afterwards...
Is there a way to change a Callback2 to a Callback3 during runtime?
//edit: After reviewing our class hierarchy I discovered, that the needed class is there and I can use it, so I changed Callback2 to Callback3 and it works fine.
Nevertheless, is it possible to add parameters to the called function beside those that come from the Callback itself, like shown above?
Just in case the parameter is an object from a class thats not known in the Callback calling function...
[Updated on: Tue, 29 July 2014 13:46] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 23:18:59 CEST 2025
Total time taken to generate the page: 0.00975 seconds
|