为什么我对此代码"no match for call"?

Why do I get "no match for call" on this code?

本文关键字:match for call no 为什么 代码      更新时间:2023-10-16

让我们看看我想这样做,我想获取树的父级,然后将节点求和并将结果放入父级中,这是多线程的。我正在使用队列来盯着可以求和的节点,等等。

我面临的问题是这个

error: no match for call to ‘(Triplets) (int&, int&, bool&, NodeT*&)’

代码来自这个

void find_triplets(NodeT *ptrRoot)
{
   if (ptrRoot != NULL)
    {
    find_triplets(ptrRoot->left);
    find_triplets(ptrRoot->right);
    cout << "find triplets and save them to the queue" << endl;
        cout << " we hit a hot spot is null the root, nothing to see here move along boys" << endl;
     if(ptrRoot->left != NULL && ptrRoot->right != NULL)
        {
        if (ptrRoot->left->done == true && ptrRoot->right->done == true)
        {
        cout << "we got one of 2 sons true so do something, this are the sons "
 << ptrRoot->left->key_value << " " << ptrRoot->right->key_value << endl;         
        cout << "sum them and put it in the father and set it to true " << endl;
        ptrRoot->key_value = ptrRoot->left->key_value + ptrRoot->right->key_value;
        ptrRoot->done = true;
        cout << "thread queue " << endl;
       triplet(ptrRoot->left->key_value, ptrRoot->right->key_value, ptrRoot->done, ptrRoot);
        qThreads.push(triplet);
        }
     }
        }

三胞胎班是这样的

class Triplets
{
public:
  int nVal1;
  int nVal2;
  NodeT *ptrNode;
  bool bUpdate;
  Triplets()
  {
    nVal2 = 0;
    nVal1 = 0;
    bUpdate = false;
    ptrNode = NULL;
  }
  ~Triplets()
  {
    delete ptrNode;
  }
  Triplets(int nVal1, int nVal2, bool bUpdate, NodeT *ptrNode)
  {
    this->nVal2 = nVal2;
    this->nVal1 = nVal1;
    this->bUpdate = bUpdate;
    this->ptrNode = ptrNode;
  }
  void form_triplet(int nval1, int nVal2, bool bUpdate, NodeT *ptrNode)
  {
    this->nVal2 = nVal2;
    this->nVal1 = nVal1;
    this->bUpdate = bUpdate;
    this->ptrNode = ptrNode;
  }
};

所以我想做的是将实际对象存储在队列中以对其进行修改,并且不要复制它。谢谢

find_triplets函数中的triplet似乎是一个Triplets实例。因此,编译器将该行解释为尝试使用这四个参数调用其 operator() 函数,但您的 Triplets 类没有这样的运算符,因此您会收到上面报告的错误消息。

您可能打算声明另一个Triplets变量(名为 triplet),或者调用 triplet.form_triplet 而不是 triplet.operator()

Triplets triplet(ptrRoot->left->key_value, ptrRoot->right->key_value, ptrRoot->done, ptrRoot);
// or
triplet.form_triplet(ptrRoot->left->key_value, ptrRoot->right->key_value, ptrRoot->done, ptrRoot);