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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:00:18+00:00 2026-05-18T20:00:18+00:00

error: no matching function for call to ‘BSTreeNode::BSTreeNode(int, int, NULL, NULL)’ candidates are: BSTreeNode::BSTreeNode(KF,

  • 0

error: no matching function for call
to ‘BSTreeNode::BSTreeNode(int, int, NULL,
NULL)’

candidates are: BSTreeNode::BSTreeNode(KF, DT&,
BSTreeNode*, BSTreeNode*) [with KF = int, DT = int]

here is how I used it:

BSTreeNode<int, int> newNode(5,9, NULL, NULL) ;

I defined it as follows:

BSTreeNode(KF sKey, DT &data, BSTreeNode *lt, BSTreeNode *rt):key(sKey),dataItem(data), left(lt), right(rt){}

what’s wrong with using my constructor this way?

i’ve been pulling out my hair all night please help me ASAP!!

  • 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-18T20:00:19+00:00Added an answer on May 18, 2026 at 8:00 pm

    Non-const references can’t be bound to an rvalue, which is what you’re trying to do with the argument 9 for the DT &data parameter.

    You’ll either need to pass in a variable that has the value 9, or you’ll need to change the argument (and the dataItem member if it’s a reference) to be DT type that gets copied by value into the object. Even if you change the reference to be const to get rid of the compiler error, you’ll have an issue with the lifetime of the argument that’s passed in if it’s a temporary (it won’t live past the constructor call, so you’ll be left with a dangling reference).

    Here’s a small example program that demonstrates the problem with binding a const reference in an object to a temporary (an int value returned from rand()). Note that the behavior is undefined, so it might appear to work under some conditions. I tested this program with debug builds on MSVC 2008 and MinGW 4.5.1:

    #include <stddef.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    template <class KF, class DT>
    class BSTreeNode {
    
    private:
        KF key;
        DT const& dataItem;
        BSTreeNode* left;
        BSTreeNode* right;
    
    public:
        BSTreeNode(KF sKey, DT const &data, BSTreeNode *lt, BSTreeNode *rt)
            : key(sKey)
            , dataItem(data)
            , left(lt)
            , right(rt)
        {}
    
        void foo() {
            printf( "BSTreeNode::dataItem == %d\n", dataItem);
        } 
    };
    
    BSTreeNode<int, int>* test1()
    {
        BSTreeNode<int, int>* p = new BSTreeNode<int, int>(5,rand(), NULL, NULL);
    
        // note: at this point the reference to whatever `rand()` returned in the
        //  above constructor is no longer valid
        return p;
    }
    
    
    int main()
    {
        BSTreeNode<int, int>* p1 = test1();
    
        p1->foo();
    
        printf( "some other random number: %d\n", rand());
    
        p1->foo();
    }
    

    An example run shows:

    BSTreeNode::dataItem == 41
    some other random number: 18467
    BSTreeNode::dataItem == 2293724
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

error: no matching function for call to ‘BSTreeNode::BSTreeNode(int, int, NULL, NULL)’ candidates are: BSTreeNode::BSTreeNode(KF,
I am getting a compiler error of: error: no matching function for call to
I'm getting an error here that says I haven't defined a method, but it
I am getting the following error when I try to call a function that
string text; getline(text.c_str(),256); 1) I am getting an error error: no matching function for
This error just started popping up all over our site. Permission denied to call
I'm trying to call a nonmember function of a derived class from a base
I cannot figure out why this segment gives unresolved overloaded function error (gcc version
I'm getting a strange error. I have a function of the following signature: template
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>

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.