我有 2 个类 TreeManager 和 TreeProducerBase。从 TreeManagerconstructor 向 TreeProducerBase 中的函数传递 TTree 对象(这是一个生成树的类)时出现错误。 注意:我将树定义为
TTree *tree_
函数调用:
tpb.initialize(&tree_);
这里,tpb 是 TreeproducerBase 类的一个对象。
这是被调用的函数。
void initialize(TTree &tree_)
显示错误如下:
error: no matching function for call to 'TreeProducerBase::initialize(TTree*&)'
我哪里做错了?
最佳答案
您正在尝试将指针到指针到 TTree 传递给需要引用到 TTree 的函数。尝试像这样重新声明它
void initialize(TTree* &tree_);
调用看起来像
tpb.initialize(tree_);
然后你可以通过简单的赋值来初始化外部指针:
void initialize(TTree* &tree_) {
tree_ = new TTree(); // or smth else
}
关于c++ - 没有匹配函数来调用 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38477598/