简体   繁体   English

没有匹配函数来调用C ++

[英]No Matching function to call C++

I have 2 classes TreeManager and TreeProducerBase. 我有2个类TreeManager和TreeProducerBase。 I am getting an error in passing an object of TTree( which is a class to make trees) to a function in TreeProducerBase from TreeManagerconstructor. 从TreeManagerconstructor将TTree对象(该类是用于创建树的类)传递给TreeProducerBase中的函数时遇到错误。 Note : I have defined tree as 注意:我将树定义为

TTree *tree_

Function call : 函数调用:

tpb.initialize(&tree_); 

Here, tpb is an object of TreeproducerBase class. 在此,tpb是TreeproducerBase类的对象。

This is the function that is being called. 这是被调用的函数。

void initialize(TTree &tree_)

It shows the error as follows: 它显示错误如下:

error: no matching function for call to 'TreeProducerBase::initialize(TTree*&)'

Where am I doing wrong? 我在哪里做错了?

You are trying to pass pointer-to-pointer-to-TTree to a function that expects reference-to-TTree. 您正试图将指向TTree的指针传递给期望引用TTree的函数。 Try redeclare it like 尝试像这样重新声明

void initialize(TTree* &tree_);

Invokation will look like 发票看起来像

tpb.initialize(tree_);

And then you can initialize outer pointer via simple assignment: 然后您可以通过简单的赋值来初始化外部指针:

void initialize(TTree* &tree_) {
    tree_ = new TTree(); // or smth else
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM