为什么我对此代码"no match for call"?
Why do I get "no match for call" on this code?
让我们看看我想这样做,我想获取树的父级,然后将节点求和并将结果放入父级中,这是多线程的。我正在使用队列来盯着可以求和的节点,等等。
我面临的问题是这个
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);
相关文章:
- 错误消息:使用"string* +="后"no match for 'operator+='"
- 在 Eclipse: "error: no match for 'operator='" 中获取错误消息
- 如何'Invalid conversion'和'no match for operator'更正这些 c++ 错误
- 为什么当我没有变量或其他任何命名的东西时"no match for 'operator==' "错误?
- 如何修复以下错误"no match for call to '(std::tr1::shared_ptr<_iobuf*>) (FILE*&)'"
- 为什么我收到以下错误:"no match for 'operator=='"?(带模板的嵌套类)
- 在命名空间内的类中使用带有运算符重载的字符串流时"no match for ‘operator>>’"
- 提升::访客操作员过载的变体"Error: no match for call to [...]"
- 如何修复C++中的"no match for operator+"?
- 运算符重载错误"no match for operator error"
- "No match for operator []"
- 如果我没有重载,为什么我会"no match for ‘operator=’"自定义类?
- 为什么编译器显示错误"no match for 'operator[]' (operand types are 'carti' and 'int')"
- 对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
- "no match for 'operator >>'"代码中是什么意思?
- "no match for ‘operator>>’ in ‘inputFile >> buffer"错误?
- 如何修复" no match for 'operator<<' in 'std::cout"错误?
- 简单迭代器差异的"No match for operator-"错误
- 使用 std::string 时"error: no match for ‘operator<<"
- 访问基于遗传算法的PNRG中的数组? " no match for operator[] "