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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:20:58+00:00 2026-05-14T15:20:58+00:00

So, the question is more or less as I wrote. I understand that it’s

  • 0

So, the question is more or less as I wrote.
I understand that it’s probably not clear at all so I’ll give an example.

I have class Tree and in it there is the class Node, and the empty constructor of Tree is written:

public class RBTree {
    private RBNode head;

    public RBTree(RBNode head,RBTree leftT,RBTree rightT){
        this.head=head;
        this.head.leftT.head.father = head;
        this.head.rightT.head.father = head;
    }

    public RBTree(RBNode head){
        this(head,new RBTree(),new RBTree());
    }

    public RBTree(){
        this(new RBNode(),null,null);
    }  

    public class RBNode{
        private int value;
        private boolean isBlack;
        private RBNode father;
        private RBTree leftT;
        private RBTree rightT;
    }
}

Eclipse gives me the error: “No enclosing instance of type RBTree is available due to some intermediate constructor invocation” for the “new RBTree()” in the empty constructor.
However, if I change the RBNode to be a static class, there is no problem.

So why is it working when the class is static.

BTW, I found an easy solution for the cunstructor:

public RBTree(){
    this.head = new RBNode();
}

So, I have no idea what is the problem in the first piece of code.

  • 1 1 Answer
  • 1 View
  • 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-14T15:20:58+00:00Added an answer on May 14, 2026 at 3:20 pm

    Basically an inner class (without the static modifier) has an implicit reference to an instance of its outer class, so it can’t be created until the outer class is created. By creating one on the call to this it can’t reference the outer class yet because the outer class isn’t constructed much at all until after the call to super. The case that works for you, the assignment to head happens after the (implicit) call to super so the class is constructed enough to get a reference to it.

    All of these rules prevent you from shooting yourself in the foot by referencing an uninitialized object and having Bad Things (TM) happen.

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

Sidebar

Related Questions

This is more or less a general question and not about any specific ORM
Really my question has more to do with the server-side scrubbing of html that's
I have an external module, that is returning me some strings. I am not
This question I have asked before and just got answer that there is an
EDIT: This question is more about language engineering than C++ itself. I used C++
This is kind of a weird question and more of an annoyance than technical
I'm iterating through a HashMap (see my earlier question for more detail) and building
Here is one more newbie question: require 'tasks/rails' I saw this line in Rakefile
I asked a related question about findbugs, but let's ask a more general question.
More detail to my question: HTML and JavaScript are called client-side code. C# and

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.