c++ - 如何在 C++ 中使用 Void 而不会出现关于参数的错误
问题描述
我正在尝试使用 C++ 创建一个简单的树,以便使用本教程在 ROOT 中运行:https ://www.niser.ac.in/sercehep2017/notes/RootTutorial_TTree.pdf 。
但是,为什么我会收到此错误:
Processing examples/tree_example1.C("../trisignal/Events/run_01/tag_1_delphes_events.root")...
input_line_9:2:2: error: no matching function for call to 'tree_example1'
tree_example1("../trisignal/Events/run_01/tag_1_delphes_events.root") /* invoking function corresponding to '.x' */
^~~~~~~~~~~~~
/mnt/c/1/MG5_aMC_v2_6_6/Delphes/examples/tree_example1.C:12:6: note: candidate function not viable: requires 0 arguments, but 1 was provided
void tree_example1 ()
我只是想在创建 TTree 的地方运行一个简单的代码。这是我的代码:
/*
#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#include "external/ExRootAnalysis/ExRootResult.h"
#else
class ExRootTreeReader;
class ExRootResult;
#endif
*/
void tree_example1 ()
{
//gSystem->Load("libDelphes");
// Create chain of root trees
//TChain chain("Delphes");
//chain.Add(inputFile);
//Open the input file and Create a simple tree
TFile *f = new TFile("eventstrial.root", "RECREATE");
TTree *tree = new TTree("T", "simple tree");
//TTree *tree = &chain;
TRandom r;
//Filling Histograms
TH1F *hist = new TH1F("hist", "", 100, 0., 2.);
//Set up the variables
Float_t px, py, pz, pt;
Double_t random;
UShort_t i;
//Set Variables to Tree's Branches
tree->Branch("px", &px, "px/F");
tree->Branch("py", &py, "py/F");
tree->Branch("pz", &py, "py/F");
tree->Branch("pt", &pt, "pt/F");
tree->Branch("random", &random, "random/D");
for (i = 0; i < 10000; i++)
{
r.Rannor(px,py);
pt = std::sqrt(px*px + py*py);
tree->Fill();
}
f->Write();
f->Close();
tree->Draw("pt>>hist");
hist->SetLineColor(3);
hist->Draw("same");
}
我在我的 ROOT 终端中输入:root -l 'examples/tree_example1.C("../trisignal/Events/run_01/tag_1_delphes_events.root")'
如果我写 root -l tree_example1.C
我收到此错误:
root [0]
Processing tree_example1.C...
*** Break *** segmentation violation
Generating stack trace...
0x00007fdcdda680a0 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const + 0x380 from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd9fae77 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) + 0xa7 from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd9fc4df in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) + 0x1df from /home/cucip/builddir/lib/libCling.so
0x00007fdcddac61f1 in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) + 0x591 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddad6084 in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x194 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddad7476 in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0xa6 from /home/cucip/builddir/lib/libCling.so
0x00007fdcddabf64b in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0x10b from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd97b68e in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd98fe72 in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdcdd984537 in <unknown> from /home/cucip/builddir/lib/libCling.so
0x00007fdce3112908 in TApplication::ExecuteFile(char const*, int*, bool) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1156 from /home/cucip/builddir/lib/libCore.so
0x00007fdce31120ac in TApplication::ProcessLine(char const*, bool, int*) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1007 from /home/cucip/builddir/lib/libCore.so
0x00007fdce35e18e2 in TRint::ProcessLineNr(char const*, char const*, int*) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:762 from /home/cucip/builddir/lib/libRint.so
0x00007fdce35e31d9 in TRint::Run(bool) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:421 from /home/cucip/builddir/lib/libRint.so
0x00007fdce3c00a0c in <unknown> from /home/cucip/builddir/bin/root.exe
0x00007fdce2571b97 in __libc_start_main + 0xe7 from /lib/x86_64-linux-gnu/libc.so.6
0x00007fdce3c00a6a in _start + 0x2a from /home/cucip/builddir/bin/root.exe
Root >
解决方案
正如你的编译器所说:
需要 0 个参数,但提供了 1 个 void tree_example1 ()
您使用一个参数而不是零调用了 tree_example1。重新定义函数以接受路径
推荐阅读
- android - Flutter:根据情况在文字上使用不同的颜色
- excel - Dir gets me a filepath, but then I can't open it or read a timestamp
- kivy - 如何在不重新输入代码 kivymd 的情况下重新使用 MDNavigationDrawer
- scala - 列出 sbt `Task` 标签
- javascript - 如何在 JS 中获取 TSV 文件并转换为 JSON
- java - 无法通过 Googles Nearby API 连接两台设备
- c# - 如何在为其设置值时检查动态属性的数据类型?
- c++ - ${workspaceFolder}\\*.cpp 显然没有被识别为 vscode tasks.json 中的有效路径
- makefile - 包括来自父目录的标题
- excel - VBA - 删除包含较少信息的重复项