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

  • Home
  • SEARCH
  • 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 8667867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:04:33+00:00 2026-06-12T18:04:33+00:00

Consider following code: namespace base { class Base { protected: class Nested { protected:

  • 0

Consider following code:

namespace base {
class Base {
    protected:
        class Nested {
            protected:
                Base* base;

            public:
                Nested(Base* _base) : base( _base ){}

                virtual void test() {
                    base->foo();
                    /*
                     * hmm.. we can use protected methods
                     */
                    base->bar();
                }
        };

    protected:
        Nested* nested;

        void bar(){}

    public:
        void foo(){}

        virtual void test() {
            nested = new Nested(this);
            nested->test();
        }
};
};

namespace inherited {
class Base : public base::Base {
    public:
        Base()
            : base::Base() {}

    protected:
        class Nested : public base::Base::Nested {
            public:
                Nested( inherited::Base* base )
                    : base::Base::Nested( base ) {}

            public:
                virtual void test() {
                    base->foo();
                    /*
                     * hmm.. and now they are not accessible
                     */
                    // base->bar();
                }
        };

    public:
        virtual void test() {
            foo();
            bar();

            nested = new Nested(this);
            nested->test();
        }
};
};

My qestions is why we have access to protected methods/properties of base::Base from base::Base::Nested but no access to the same methods/properties of inherited::Base from inherited::Base::Nested?

The only thing I could suppose is that base::Base is a kind of global scope for base::Base::Nested thus they are accessible. inherited::Base is a kind of global scope for inherited::Base::Nested and protected members of base::Base are not accessible. However, public inheritance should not change scope of visibility and the reason of access inability is unclear for me.

  • 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-12T18:04:34+00:00Added an answer on June 12, 2026 at 6:04 pm

    The issue seems to be the type of the stored pointer and not access rights. Consider this:

    class B {
    protected:
      void bar();
    };
    
    class D : public B {
    public:
      void call() {
        this->bar(); // works
        static_cast<B*>(this)->bar(); // does not work
      }
    };
    

    The situation is similar when you try to call bar through the
    pointer that is stored in the base.

    You can work around this issue by down-casting base, but I would strongly object to that.

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

Sidebar

Related Questions

Consider the following sample code: class Base { public: void f(); virtual void vf();
Consider the following short code snippet. namespace B { public class Foo { public
Consider the following sample code: #include <iostream> using namespace std; class base { public:
Consider the following sample code. #include <iostream> using namespace std; class base { public:
Consider the following code: class A { public: void foo() { auto functor =
Consider the following code: using System; namespace ConsoleApplication2 { class Program { static void
Consider the following code: namespace DisposeTest { using System; class Program { static void
Consider the following code: #include <iostream> using namespace std; class Test { static int
Consider the following code: namespace ConsoleApplication1 { class Program { static void Main(string[] args)
consider the following class declarations: namespace X { template<class T> class Foo { public:

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.