让我们看看我想要这样做,我想得到一个树的父,然后对节点求和并将结果放在父节点中,这是多线程的。我正在使用队列来查看可以求和的节点等。
我面临的问题是这个
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;
}
};
所以我想要做的是将实际对象存储在队列中进行修改,不要复制它。感谢
答案 0 :(得分: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);