1

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

我面临的问题是这个

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;
  }
};

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

4

1 回答 1

1

看来triplet您的find_triplets函数中是一个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);
于 2012-06-18T12:56:03.410 回答