Pedro.Alonso
Pedro.Alonso

Reputation: 1005

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

Let's see I want to do this, i want to get the parent of a tree, then sum the nodes and putthe result in the parent, this is multithreaded. I'm using a queue to stare the nodes thata can be sum, etc.

The problem I'm facing is this

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

The code is coming from is this

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

        }
     }
        }

The triplet class is like so

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

So what I want to do is to store the actual object in the queue to modify it, and don't make copies of it. Thanks

Upvotes: 1

Views: 96

Answers (1)

Rob Kennedy
Rob Kennedy

Reputation: 163357

It appears that triplet in your find_triplets function is a Triplets instance. The compiler interprets that line, therefore, as an attempt to invoke its operator() function using those four arguments, but your Triplets class has no such operator, so you get the error message reported above.

You probably meant either to declare another Triplets variable (named triplet), or to call triplet.form_triplet instead of 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);

Upvotes: 1

Related Questions