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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:49:55+00:00 2026-05-27T02:49:55+00:00

I have a set of classes class myClassA{ friend class MyFatherClass; }; class MyFatherClass{

  • 0

I have a set of classes

class myClassA{
    friend class MyFatherClass;
};

class MyFatherClass{
    ...
};

class MySonClass : public MyFatherClass {
};

My father class can access all the methods of the class MyClassA.
I would like as well that all the class which will extend MyFatherClass will be able to call such methods.

I can see just 2 options:

  1. at any time I go to add in myClassA the new class as a friend. ( I do not like it )
  2. I create some protected wrapper in the father function to access the method from the class myClassA. (slightly better but i still do not like it as well because i have to create a new wrapper at any time a new method is created in myClassA)

Do you have any idea for a more elegant solution to the problem?

Thanks

  • 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-27T02:49:56+00:00Added an answer on May 27, 2026 at 2:49 am

    First off… what does elegant mean? Less code for you to write? I suggest you don’t compromise when it comes to readability.

    Using friendship should not be a decision taken lightly. There are numerous threads on SO dealing with this, but here I’ll just assume you already know what this implies.

    Option 1) is a lot more readable. When someone sees the class, they will directly know who has access to it. Code should be expressive, and this option describes the intent perfectly.

    Option 2) is a bit of an overkill. You’re writing a wrapper just so you can access some functions… why not make them public to start with, since the wrapper has public access. It’s just an added layer of abstraction for nothing.

    You should first think about functionality (both work), expressiveness and readability (option 1 is definitely better here).

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

Sidebar

Related Questions

I have two classes class A { public string something { get; set; }
I have two classes: public class MultilingualString { public int Id { get; set;
I have a set of classes like this: class A { public: int DoIt()
I have two classes set up as follows: class Point { protected: double coords[3];
I have a abstract base class A and a set of 10 derived classes.
Present Scenario : I have a set of classes that all take a common
I have helper component used in multiple classes. This is typical scenario: public class
First of all, sorry for my English... I have something like this: public class
Suppose that I have the following HBM mapping: <class name=Student table=student> <set name=classes table=student_classes
Lets say that I have the two following classes public class OtherClass { 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.