Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:43:26+00:00 2026-06-06T05:43:26+00:00

Hello I have this code class Triplets { public: int nVal1; int nVal2; NodeT

  • 0

Hello I have this code

class Triplets
{
public:
int nVal1;
int nVal2;
NodeT *ptrNode;
bool bUpdate;

Triplets()
{
    cout << "creating empty triplet" << endl;
    nVal2 = 0;
    nVal1 = 0;
    bUpdate = false;
    ptrNode = NULL;
}

~Triplets()
{
    cout << "destroying triplet" << endl;
    delete ptrNode;
}

Triplets(int nVal1, int nVal2, bool bUpdate, NodeT *ptrNode)
{
    cout << "creating triple with values" << endl;
    this->nVal2 = nVal2;
    this->nVal1 = nVal1;
    this->bUpdate = bUpdate;
    this->ptrNode = ptrNode;
}
 };

This usage

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;
        Triplets triplet(ptrRoot->left->key_value, ptrRoot->right->key_value, ptrRoot->done, ptrRoot);
        qThreads.push(triplet);
       }
     }
     }
    }

And this main

MyThread mt;
mt.start();
mt.run();
cout << "sum = " << mt.sum(&bt) << endl;
THREADS_HOW_MANY = boost::thread::hardware_concurrency();
std::cout << THREADS_HOW_MANY << std::endl;

while (!bt.Values_to_do.empty())
{
    cout << "da vals to sum are these " << bt.Values_to_do.front() << " and aready done " << bt.values_done.front() << endl;
    bt.Values_to_do.pop();
    bt.values_done.pop();
}

  while(!mt.qThreads.empty())
{
cout << "da triplet are " << mt.qThreads.front().nVal1 << " " <<mt.qThreads.front().nVal2 << " "
        << mt.qThreads.front().ptrNode << " " << mt.qThreads.front().bUpdate
        << endl;
mt.qThreads.pop();

}

All of this give me this result(obviously wrong)

  done lets chek
  find triplets
  find triplets and save them to the queue
   we hit a hot spot is null the root, nothing to see here move along boys
   find triplets and save them to the queue
    we hit a hot spot is null the root, nothing to see here move along boys
 find triplets and save them to the queue
 we hit a hot spot is null the root, nothing to see here move along boys
 we got one of 2 sons true so do something, this are the sons 2 8
 sum them and put it in the father and set it to true 
 thread queue 
 creating triple with values
 destroying triplet
 find triplets and save them to the queue
 we hit a hot spot is null the root, nothing to see here move along boys
 find triplets and save them to the queue
 we hit a hot spot is null the root, nothing to see here move along boys
find triplets and save them to the queue
we hit a hot spot is null the root, nothing to see here move along boys
 we got one of 2 sons true so do something, this are the sons 11 15
 sum them and put it in the father and set it to true 
thread queue 
creating triple with values
destroying triplet
find triplets and save them to the queue
 we hit a hot spot is null the root, nothing to see here move along boys
 we got one of 2 sons true so do something, this are the sons 19976608 19976464
 sum them and put it in 
 the father and set it to true 
 thread queue 
 creating triple with values
 destroying triplet
 the gran total is 19976320

Now my q is why is my triplet object no being added to the queue and is being destroyed instead, that is what is causing the sum to come out all messed up. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:43:27+00:00Added an answer on June 6, 2026 at 5:43 am

    Tl;dr – what pops up is that you have a destructor that manages memory:

    ~Triplets()
    {
        cout << "destroying triplet" << endl;
        delete ptrNode;
    }
    

    yet no copy constructor and assignment operator. Try implementing those.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have following c++ code class classBase { public: int get1(){return 1;} int
Lets say I have this code: <?php class hello { var $greeting = hello;
So I currently have this code: (ns contact-form.core (:gen-class)) (def foo Hello World!) (defn
Hello i have this code class Test(object): def start_conn(self): pass def __init__(self): self.conn =
I Have this code : MainPage.cs public class MainPage : System.Web.UI.Page { public string
I have this code: #include <iostream> using namespace std; class FooA { public: virtual
I have this HTML code: <p>Hello <span class=hide style=display:none>there</span> jquery</p> <button class=toggle>Toggle</button> <p>Hello <span
I have this snippet of the code: public class Main_class { public static void
For example, I want to have code like this: class Class1 { Class2.print(Hello there.);
Say you have this code: <div class=hello> <div class=cat dog/> </div> <div class=notASibling />

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.