Hi again, I’m trying to implement an AddExec in a class, which will create a TCanvas and do things when the mouse does things. I would additionally like the function which is added via AddExec to take an argument. Is that possible?
Here’s a MWE of my first attempt, which failed. The argument is an integer “num” or “my_num”. I hope it’s clear that I really don’t understand what AddExec is doing under the hood – I think there’s no way my simple int my_num = 2 declaration could’ve worked, and yet I try.
root [0] gInterpreter->Declare("#include \"MyClass.hh\"");
root [1] auto obj = new MyClass();
root [2] obj->Run();
root [3] input_line_45:2:2: error: cannot initialize an array element of type 'void *' with an rvalue of type
'void (*)(int)'
MyClass::MouseEvent(my_num)
^~~~~~~~~~~~~~~~~~~
Hi @couet. I’m using an integer here as an example – the thing which I actually want to pass is not an integer. It’s a std::vector, or maybe a std::map. So a string representation is not helpful.
Okay. So it is not feasible to pass an argument to a function via AddExec.
Do you know if it’s possible to declare a global variable my_num somewhere, which the function MouseEvent will then be aware of? Or does this conflict with MouseEvent needing to be static?