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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:43:35+00:00 2026-05-20T18:43:35+00:00

If C++.NET allowed multiple inheritance, I would have my common methods in a class

  • 0

If C++.NET allowed multiple inheritance, I would have my common methods in a class and derive from it.

I have classes derived from Panel, Label, TabControl … which have the same methods exactly.

How can I structure my C++ code so that I only write my common methods once?

Here is a simple example of a property I want to add to each derived class. Extension methods sound ideal, but don’t exist in C++.

private: int panelBottomMargin;
public:
    [Browsable(true)]
    [CategoryAttribute("Layout"), DescriptionAttribute(
        "Specify the gap between the last control and the bottom of the panel"),
    DefaultValueAttribute(panelBottomMarginDefault)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility::Visible)]
    property int PanelBottomMargin
    {
        int get() { return this->panelBottomMargin; }
        void set(int margin) { this->panelBottomMargin = margin; }
    }
  • 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-20T18:43:35+00:00Added an answer on May 20, 2026 at 6:43 pm

    I can’t quite make out for sure what you mean by “common methods” here, but generally speaking namespace level non-member functions are the best way to do that (see pretty much every algorithm in the standard library).

    If it actually needs access to private attributes of your class then it’s probably not a common method and should be implemented in the level of inheritance where the attribute it operates on exist.

    It’s almost certainly an abuse of inheritance to put common methods into a class that you then inherit from: Use inheritance to extend, NOT to reuse.

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

Sidebar

Related Questions

In .net we are not allowed to have shared function/methods in abstract classes and
I have an ASP.NET application that uses Session.SessionID to prevent multiple users viewing the
I have an ASP.NET page that requires the ability to have users enter multiple
I have created a web part in asp.net application and allowed user to change
I have a ASP.NET MVC 2 app I am building and users are allowed
.NET 3.5, C# I have a web app with a search feature. Some of
I'm wondering why the 'partial class' concept even exists in C#/VB.NET. I'm working on
I have a situation in which the ideal relationship, I believe, would involve Value
I have small problem with my .net 2.0 winforms application. I want to embed
i am asking myself if it would be dangerous on a asp.net page´s codebehind

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.