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

Related Questions

Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey all, here is the issue I am currently trying to work through. We
Hey all, I'm wondering if anyone has ever used a tool which will take
Hey guys I've been trying all day to get an ant file to automatically
Hey everyone, I am having a problem with a website I'm trying to build;
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey all, I have something of an interesting requirement for my project. I need
Hey all. We're sending quite a few emails (around 23k) using IIS6 SMTP service
Hey all - I have an app where I'm authenticating the user. They pass
Hey all, I'm pulling my hair out on this one. I've checked all my

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.