Interpret a string containing C++ code?


I would like to write a piece of code that does something like this:

string input="3*a + v*b"; TObject o = interpret(input);

Where in this case for example a and b are TVector3 and v is a TRotation.

I imagine that CINT does exactly this…

Is there a simple way in root to do this? (calling CINT?)



use gROOT->ProcessLine(), see Remember to also declare your variables at that level (i.e. via ProcessLine). You can pass variables from the outer (calling) level to the ProcessLine level using

TMatrix a(...); gROOT->ProcessLine(Form("TMatrix* pa=0x%x;", &a)); // bring "a" to sub interpreter by passing its address gROOT->ProcessLine("if (pa) pa->Print();");