让我们看看我想做这个,我想得到一棵树的父节点,然后对节点求和并将结果放在父节点中,这是多线程的。我正在使用队列来查看可以求和等的节点。
我遇到的问题是这个
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);
}
}
}
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);
关于c++ - 为什么我在这段代码上得到 "no match for call"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11083171/