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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:47:56+00:00 2026-06-04T15:47:56+00:00

class BaseA{}; , class DerivedB{}; class DerivedC{}; DerivedB can be derived from BaseA :

  • 0

class BaseA{}; , class DerivedB{}; class DerivedC{};

DerivedB can be derived from BaseA : Want to allow: class DerivedB: public BaseA

But, if someone tries to do DerivedC : public BaseA ==> want to restrict this.

Is it possible?

  • 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-06-04T15:47:59+00:00Added an answer on June 4, 2026 at 3:47 pm

    You can make all BaseA‘s constructors private and add DerivedB as a friend of BaseA‘s.

    class BaseA
    {
        friend class DerivedB;
    private:
        BaseA();
    };
    class DerivedB : BaseA
    {
    };
    class DerivedC : BaseA  //error - I get it when I try to create an object in MSVS
                            //but in principle it works
    {
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out how to call a base class method from a derived
I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC
Since in C#, classes can only be derived from a single class, is there
I want to store multiple class types derived from the same base class in
How can I call a derived function from a base class? I mean, being
Why can't I cast a base class instance to a derived class? For example,
I want to call a overridden method from a base class method called by
Like this: public class remoteStatusCounts : RemoteStatus { public int statusCount; public remoteStatusCounts(RemoteStatus r)
I have this code structure: public abstract class ContentEntryBase { public string UniqueIdentifier; public
I have a base class that I want to look like this: class B

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.