我使用的是Cern ROOT版本5.34,我在使用函数时遇到了问题。始终显示相同的消息错误。
例如(使用一个非常简单的函数):
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 5.34/36 5 April 2016 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
ROOT 5.34/36 (v5-34-36@v5-34-36, Apr 05 2016, 10:25:45 on win32)
CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] #include <iostream>
Note: File "iostream" already loaded
root [1] using namespace std;
root [2] void hello(){cout << "Hi!" << endl;}
Limitation: Function can not be defined in a command line or a tempfile
You need to write it in a source file (tmpfile)(1)
*** Interpreter error recovered ***
root [3]
我该如何解决这个问题?
答案 0 :(得分:0)
如果您使用支持所有C ++ 11功能的root 6,则可以改为定义lambda函数,如此
auto hello = [](){ cout << "Hi!" << endl; };
然后,您可以像常规功能一样调用它
hello();