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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:33:27+00:00 2026-05-17T18:33:27+00:00

From link http://www.coolinterview.com/interview/10842/ Is there any way to write a class such that no

  • 0

From link http://www.coolinterview.com/interview/10842/

Is there any way to write a class such that no class can be inherited from it ?

From suggestions in the above link, i tried below code

class A
{
    A(){}
    ~A(){}
    A(const A&);
    A& operator=(const A&);
};

class B: public A
{
};

The above code doesn’t produce any error.
If i try to instantiate B like below

int main()
{
    B ob;
}

then it gives error

error C2248: ‘A::A’ : cannot access
private member declared in class ‘A’

So inheritance its allowing but instantiation its not allowing.

Is there any other way of blocking inheritance itself ?

  • 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-17T18:33:28+00:00Added an answer on May 17, 2026 at 6:33 pm

    There is no equivalent to the final keyword in Java or C♯’s sealed in C++. You can certainly prevent inheritance by making the class constructors private, or by following liaK’s link and having a class subclass a class that has private constructors and is its friend.

    In general though:

    You can just make your destructor non-virtual to signal that you do not intend for the class to be polymorphic, and document that this is your intention. Of course, if users of your class decide to ignore this, they could run into problems of their own for their hubris. 😉

    Additionally: http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.11

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

Sidebar

Related Questions

Please view image of Google maps fig 1. from the link below: http://www.androidpatterns.com/uap_pattern/search-%E2%80%93-main-menu Currently
I try to do this: posts[fbposts[fbpost].id] = ({ name: fbposts[fbpost].from.name, link: http://www.facebook.com/ + fbposts[fbpost].from.id,
This is the output to my program from this link (http://www.rottentomatoes.com/movie/box_office.php). As you can
Hey guys i have been trying to download it from the below link http://www.enterprisedb.com/products-services-training/pgdownload
I am trying to make an FBconnect application. I got a link http://www.mobisoftinfotech.com/blog/android/845/ From
I've seen this link: http://www.lucidimagination.com/Community/Hear-from-the-Experts/Articles/Content-Extraction-Tika What I got is pure text without any style
I have a VBScript copied from the link http://www.robvanderwoude.com/vbstech_ui_password.php In the existing VBSscript I
I am using the style sheets for the gridview from this link http://www.cyberslingers.com/Sandbox/GridView.aspx It
I have a code download image from link http://www.bitrepository.com/download-image.html When start is link format:
From where can I download MAPI33.dll. I got the link http://www.mapi33.adexsolutions.com/ from a site

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.