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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:49:11+00:00 2026-05-25T23:49:11+00:00

When coding classes that are tightly coupled functionally, but where you want a simple

  • 0

When coding classes that are tightly coupled functionally, but where you want a simple interface to the rest of the world, it would be neat if I could do something like this:

class log
{
private:
  log_context& cont;
public:
  create_log_section(std::string name)
  {
    cont.create_log_section(name);// this is fine! It's "internal"
    cont.this_is_private();       // doesn't compile. Don't want anyone touching my privates!
  }
};

class log_context
{
internal:
  void create_log_section(std::string name);
private:
  void this_is_private();
internal friend log;             // Wow, possible?
}

Now, this would allow log to access the relevant parts of context, but not the private ones. The rest of the program should use log to add any context. It could also pass around strongly typed log_contexts between logs without having any extra power. I realize that this particular solution is not possible, but what are some common ones, if any?

  • 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-25T23:49:11+00:00Added an answer on May 25, 2026 at 11:49 pm

    You can use an internal class to do so

    class log_context
    {
        class internal
        {
            friend log;
    
            static void create_log_section( log_context & context, std::string name)
            {
                context.create_log_section( name );
            } 
        }
    
        private:
            void create_log_section(std::string name);
            void this_is_private();
    }
    
    class log
    {
        private:
    
        log_context& cont;
    
        public:
    
        void create_log_section(std::string name)
        {
            log_context::internal::create_log_section( cont, name );// this is fine! It's "internal"
        }
    };
    

    As internal as only private static functions, only its friends can access it

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

Sidebar

Related Questions

In my early coding days, I would tend to group classes that functioned in
I'm coding a site that's using tags. Two other classes (Foo and Bar) both
I have a set of classes that work together (I'm coding in javascript). There
For some derived classes, I want to ensure that one of two overloaded abstract
Should we have a team coding standard that the names of abstract classes have
I want to add panel classes to a sizer in a frame class that
I can develop an application/project. But that is not in the correct coding standard.
I have a abstract base class that I have many inherited classes coming off
I am trying to learn PHP classes so I can begin coding more OOP
After coding and testing a Java application (lets say with Eclipse, but not necessarily)

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.