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 581529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:35:18+00:00 2026-05-13T14:35:18+00:00

Hey all, so I am trying to build a simple binary tree that has

  • 0

Hey all, so I am trying to build a simple binary tree that has two keys and evaluates the sum for its sorting. Here is what it’s looking like:

struct SumNode
{
    int keyA;
    int keyB;
    SumNode *left;
    SumNode *right;
};

class SumBTree
{
    public:
        SumBTree();
        ~SumBTree();

        void insert(int, int);
        SumNode *search(int, int);
        SumNode *search(int);
        void destroy_tree();

    private:
        SumNode *root;

        void insert(int,int, SumNode*);
        SumNode *search(int,int, SumNode*);
        SumNode *search(int, SumNode*);
        void destroy_tree(SumNode*);
};


SumBTree::SumBTree()
{
    root = NULL;
}

SumBTree::~SumBTree(){};


void SumBTree::insert(int a, int b, SumNode *leaf)
{
    int sum = a + b;
    int leafsum = leaf->keyA + leaf->keyB;

    if (sum < leafsum)
    {
        if (leaf->left != NULL)
        {
            insert(a,b, leaf->left);
        }
        else
        {
            leaf->left = new SumNode;
            leaf->left->keyA = a;
            leaf->left->keyB = b;
            leaf->left->left = NULL;
            leaf->left->right = NULL;
        }
    }
    else
    {
        if (leaf -> right != NULL)
        {
            insert(a,b, leaf->right);
        }
        else
        {
            leaf->right = new SumNode;
            leaf->right->keyA = a;
            leaf->right->keyB = b;
            leaf->right->left = NULL;
            leaf->right->right = NULL;
        }
    }
}

SumNode *SumBTree::search(int a, int b, SumNode *leaf)
{
    if (leaf != NULL)
    {
         if (a == leaf->keyA && b == leaf->keyB)
            return leaf;

        int sum = a + b;
        int leafsum = leaf->keyA + leaf->keyB;

        if (sum < leafsum)
            return search(a, b, leaf->left);

        return search(a, b, leaf->right);


    }
    return NULL;
}


SumNode *SumBTree::search(int sum, SumNode *leaf)
{
    if (leaf != NULL)
    {
        int leafsum = leaf->keyA + leaf->keyB;

        if (sum == leafsum)
            return leaf;

        if (sum < leafsum)
            return search(sum, leaf->left);

        return search(sum, leaf->right);


    }
    return NULL;
}

void SumBTree::destroy_tree(SumNode *leaf)
{
    if(leaf != NULL)
    {
        destroy_tree(leaf->left);
        destroy_tree(leaf->right);
        delete leaf;
    }
}


void SumBTree::insert(int a, int b)
{
    if (root != NULL)
    {
        insert(a,b, root);
    }
    else
    {
        root = new SumNode;
        root->keyA = a;
        root->keyB = b;
        root->left = NULL;
        root->right = NULL;
    }
}

SumNode *SumBTree::search(int a, int b)
{
    return search(a, b, root);
}

SumNode *SumBTree::search(int sum)
{
    return search(sum, root);
}

void SumBTree::destroy_tree()
{
    destroy_tree(root);
}

I went to test it out, using this:

#include <iostream>
#include "SumBTree.h"

using namespace std;

int main()
{
    cout << "Initializing Tree" << endl;
    SumBTree sbt();

    cout << "Inserting (2,3)" << endl;
    sbt.insert(2,3);



    cout << "Hello world!" << endl;
    return 0;
}

But whenever I try to build it I get the following error:

||=== BTree, Debug ===|
C:\Users\Axel\Desktop\coding\C++ Projects\BTree\main.cpp||In function int main()':|
C:\Users\Axel\Desktop\coding\C++ Projects\BTree\main.cpp|12|error: request for member
insert’ in sbt', which is of non-class typeSumBTree ()()’|
||=== Build finished: 1 errors, 0 warnings ===|

I can’t figure out what I’m doing wrong! Is it the overloaded functions? I don’t get it.
Does anyone here know?

  • 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-05-13T14:35:19+00:00Added an answer on May 13, 2026 at 2:35 pm

    you need to replace SumBTree sbt(); with SumBTree sbt;

    Right now it thinks sbt isn’t a class. If there are no parameters in a constructor don’t use empty brackets.

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

Sidebar

Ask A Question

Stats

  • Questions 379k
  • Answers 379k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Generally I would expect that your base class would be… May 14, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer The anchorPoint is relative to the bounds of the parent.… May 14, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer There is no MySQL function like this for PHP, however… May 14, 2026 at 9:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.