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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:00:53+00:00 2026-05-24T01:00:53+00:00

So my Idea is simple – to have a class that can have its

  • 0

So my Idea is simple – to have a class that can have its own public methosds and a nested class that would forvard only some of that public methods (pseudocode):

class API
{
public:
    go();
    stop();
    friend class B
    {
    public:
        void public_request()
        {
            request();
        }
        void public_go()
        {
            go()
        }
    };
private:
    void request(){}
};

Is it possible to implement such nested class in C++ and how?

  • 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-24T01:00:54+00:00Added an answer on May 24, 2026 at 1:00 am

    Yes, but you have to provide an instance of the outer class when you create the inner one… the two types are [mostly] independant, so B is not associated with any specific instance of API.

    More pseudo-code

    struct API {
       void go();
       struct B {
           B(API& api) : api(api) { }
           void go() { api.go(); }
       };
    };
    
    API a;
    B b(a);
    b.go();
    

    Alternatively, you can pass an instance of API to B‘s function [B::go(API&)]

    struct API {
       void go();
       struct B {
           void go(API& api) { api.go(); }
       };
    };
    
    API a1, a2;
    B b;
    b.go(a1);
    b.go(a2);
    

    Further, API does not contain an instance of B unless you explicitely add an instance.

    struct API {
      struct B { };
      B b;
    };
    

    Also, note that B does not need to be granted friendship by API. As an inner class, B can already access APIs private/protected members. The converse is not true, however… API can not access Bs private/protected members unless B grants it permission.

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

Sidebar

Related Questions

Simple idea: I have two images that I want to merge, one is 500x500
the simple idea we have about GUID is that it's unique, but how GUIDs
I have a simple idea for a small web application that I'd like to
I have no idea how to do this simple task. LightSwitch's Solution Explorer is
a possibly simple problem, but weird why I have no idea how to do
I have a simple task to do using PHP dealing with pagination. The idea
how would I map this relationship in NHibernate (I'm using the simple idea of
In Java is there an object like a Set that can contain only unique
I have a simple idea: I want to draw a line in 3d space
I want do some other item stacking but i dont have idea how simple

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.