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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:27:57+00:00 2026-06-18T01:27:57+00:00

I read some posts about Nested Classes in our community and outside and I’m

  • 0

I read some posts about Nested Classes in our community and outside and I’m pretty confused.

As far as I understand, in C++, Nested Classes aren’t not any different from separate/independent classes.

While I was trying to understand the conecpt better I wrote a simple code and I found out that an inner class can access an outer class without being given friendship from the outer class.

For example:

class Outer {
private : // default access modifier
    int x;
    static int sx;
public:
    class Inner {
    public:
        void changeOuterDataMemberValues(int value) {
            sx = value; // changes the private static data member of Outer.

            Outer out;
            out.x = value; // changes the private data member via object (not via class!)
        }
        void printMyOuterDataMember()  {
            cout << sx; // prints the private data member of Outer.
        }
    };
};


class Lonesome {
    void tryingToChangeDataMemberValue(int value) {
        Outer::sx = value; // cannot change the private static data member of Outer.
    }
};

int Outer::sx;

You can see that the Inner class which is nested in the Outer class has access to its(the Outer class) data members whilst the Lonesome as independent class cannot access the Outer class data member.

I apologize if this is a duplicate or stupid question, but I just want to confirm with you guys that there is a difference between a Nested Class and independent class (two different classes which don’t have inner / outer relationship).

Thank you all,
Syndicator =]

  • 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-06-18T01:27:58+00:00Added an answer on June 18, 2026 at 1:27 am

    There is a difference between C++03 and C++11 in this regards. So the answer varies depending on which compiler you are using.

    If you are using a C++03 compliant compiler then:

    Nested class cannot access all members of the enclosing class.

    If you are using C++11 compliant compiler then:

    Nested class can access all members of the enclosing class. Nested class is treated as just another member of the class.

    C++03 Standard 11.8 Nested classes:
    §1

    The members of a nested class have no special access to members of an enclosing class, nor to classes or functions that have granted friendship to an enclosing class; the usual access rules shall be obeyed.

    C++11 Standard 11.7 Nested Classes:

    A nested class is a member and as such has the same access rights as any other member.

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

Sidebar

Related Questions

I am confused about the castle wcf facility registration. I read some blog posts
Today I read some posts about the 'autocomplete' browser generated in the text fields,
I have read some posts about this topic and the answers are comet, reverse
I'm not familiar with Capistrano at all, I've just read some basic posts about
I have read some posts on here about not mixing parameters when passing into
I have read some posts about the differences between these 3 relationships and I
Just read some posts about how wonderful Silverlight 3.0 is, including that it uses
I've read some posts about this but none cover this issue. I guess its
I've read quite some posts about webkit browsers having issues with images. I couldn't
I have read some posts on this website about using drawInRect instead of the

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.