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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:51:10+00:00 2026-05-15T09:51:10+00:00

Please see the example code below: class A { private: class B { public:

  • 0

Please see the example code below:

class A
{
private:
    class B
    {
    public:
        foobar();
    };
public:
    foo();
    bar();
};

Within class A & B implementation:

A::foo()
{
    //do something
}

A::bar()
{
    //some code
    foo();
    //more code
}

A::B::foobar()
{
    //some code
    foo(); //<<compiler doesn't like this
}

The compiler flags the call to foo() within the method foobar(). Earlier, I had foo() as private member function of class A but changed to public assuming that B’s function can’t see it. Of course, it didn’t help. I am trying to re-use the functionality provided by A’s method. Why doesn’t the compiler allow this function call? As I see it, they are part of same enclosing class (A). I thought the accessibility issue for nested class meebers for enclosing class in C++ standards was resolved.

How can I achieve what I am trying to do without re-writing the same method (foo()) for B, which keeping B nested within A?

I am using VC++ compiler ver-9 (Visual Studio 2008). Thank you for your help.

  • 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-15T09:51:11+00:00Added an answer on May 15, 2026 at 9:51 am

    foo() is a non-static member function of A and you are trying to call it without an instance.
    The nested class B is a seperate class that only has some access privileges and doesn’t have any special knowledge about existing instances of A.

    If B needs access to an A you have to give it a reference to it, e.g.:

    class A {
        class B {
            A& parent_;
        public:
            B(A& parent) : parent_(parent) {}
            void foobar() { parent_.foo(); }
        };
        B b_;
    public:
        A() : b_(*this) {}
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 519k
  • Answers 519k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should make access to the connections field thread safe.… May 16, 2026 at 8:29 pm
  • Editorial Team
    Editorial Team added an answer Found the answer from the httpclient mailing list... Google doesn't… May 16, 2026 at 8:29 pm
  • Editorial Team
    Editorial Team added an answer Do you mean scalable as in it works with multiple… May 16, 2026 at 8:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Please see an example of my code below: CODE UPDATED public class ScrollableCheckboxList {
Please review the example code below, I have a class file that is loaded
So Im trying to make an object dynamically, please see below code from my
**Updated: (See below)**I have been looking around for couple of days and can't find
This is more of an architecture/best practices question than anything else, so please feel
EDIT: I figured out how to solve the specific code broken part of my
I have an Android app where I want to check to see if an
In a windows forms application, a property change that triggers INotifyPropertyChanged, will result in
I have a few questions (so far) with the the LocationManager on Android and
I am just learning NHibernate. I have been using examples from the documentation 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.