well, that's it: i want to start a function by its name, which is saved in a string as it is possible in php. for example you have an edit-field where you type in the name of the function as a string und click on a button and exactly the function you wrote in will be started. you could also make it with an if-clause, but i want the string to be included as source-code. do you understand what i mean?
here is how it works in php (for example the add-function for an calculator):
(the function is part of the class calc with the properties $n1 and $n2)
function add($n1, $n2)
{
return ($n1 + $n2);
}
$the_function = "add"; // set the_function
$calc->n1 = 2; // set numbers
$calc->n2 = 4;
$result = $calc->$the_function(); // start the function
$print "$result" // 6 is printed
you see: "$calc->$the_function();" is automatically replaced with "$calc->add();". so $result will be 6;
is something like this possible in c++?
thank you for your help.
here is how it works in php (for example the add-function for an calculator):
(the function is part of the class calc with the properties $n1 and $n2)
function add($n1, $n2)
{
return ($n1 + $n2);
}
$the_function = "add"; // set the_function
$calc->n1 = 2; // set numbers
$calc->n2 = 4;
$result = $calc->$the_function(); // start the function
$print "$result" // 6 is printed
you see: "$calc->$the_function();" is automatically replaced with "$calc->add();". so $result will be 6;
is something like this possible in c++?
thank you for your help.