【问题标题】:Cern ROOT 5.34 error message using functions使用函数的 Cern ROOT 5.34 错误消息
【发布时间】:2017-06-03 10:33:05
【问题描述】:

我使用的是 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]

我该如何解决这个问题?

【问题讨论】:

  • 这可能是一个提示:Limitation: Function can not be defined in a command line or a tempfile You need to write it in a source file (tmpfile)(1)

标签: c++ function root-framework


【解决方案1】:

如果你使用支持所有 C++11 特性的 root 6,你可以定义一个 lambda 函数,像这样

auto hello = [](){ cout << "Hi!" << endl; };

你可以像普通函数一样调用它

hello();

【讨论】:

    猜你喜欢
    • 2018-05-25
    • 1970-01-01
    • 2011-04-26
    • 2012-05-31
    • 2015-09-27
    • 2019-08-16
    • 2011-11-23
    • 2020-10-21
    • 1970-01-01
    相关资源
    最近更新 更多