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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:19:06+00:00 2026-05-22T20:19:06+00:00

In C++, an object refers to itself via this . But how does an

  • 0

In C++, an object refers to itself via this.

But how does an instance of an inner class refer to the instance of its enclosing class?

class Zoo
{
    class Bear 
    {
        void runAway()
        {
            EscapeService::helpEscapeFrom (
                this, /* the Bear */ 
                ??? /* I need a pointer to the Bear's Zoo here */);
        }
    };
};

EDIT

My understanding of how non-static inner classes work is that Bear can access the members of its Zoo, therefore it has an implicit pointer to Zoo. I don’t want to access the members in this case; I’m trying to get that implicit pointer.

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

    Unlike Java, inner classes in C++ do not have an implicit reference to an instance of their enclosing class.

    You can simulate this by passing an instance, there are two ways :

    pass to the method :

    class Zoo
    {
        class Bear 
        {
            void runAway( Zoo & zoo)
            {
                EscapeService::helpEscapeFrom (
                    this, /* the Bear */ 
                    zoo );
            }
        };
    }; 
    

    pass to the constructor :

    class Zoo
    {
        class Bear
        {
            Bear( Zoo & zoo_ ) : zoo( zoo_ ) {}
            void runAway()
            {
                EscapeService::helpEscapeFrom (
                    this, /* the Bear */ 
                    zoo );
            }
    
            Zoo & zoo;
        };
    }; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What does 'this' keyword refer to when used in global object? Let's say for
How can I make a ForeignKey refer back to the object itself? I'm trying
How does the garbage collector determine whether an object is garbage? Does it refer
Object doesn't support this property or method It's this line. pthumb = $(#pthumb).attr(src); Does
I want to refer to an object within the object itself. The following is
I know the dollar sign $ refers to the jQuery object but I don't
If I have a Range object--for example, let's say it refers to cell A1
I would like to know how I can refer to a list item object
Object o = new Long[0] System.out.println( o.getClass().isArray() ) System.out.println( o.getClass().getName() ) Class ofArray =
Object slicing is some thing that object looses some of its attributes or functions

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.