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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:31:10+00:00 2026-05-25T14:31:10+00:00

Are there any circumstances in which it is legitimate for a derived class to

  • 0

Are there any circumstances in which it is legitimate for a derived class to have a non-virtual destructor? A non-virtual destructor signifies that a class should not be used as a base-class. Will having a non-virtual destructor of a derived class act like a weak form of the Java final modifier?

I am especially interested in the case where the base class of the derived class has a virtual destructor.

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

    Are there any circumstances in which it is legitimate for a derived
    class to have a non-virtual destructor?

    Yes.

    A non-virtual destructor signifies that a class should not be used as
    a base-class.

    Not really; a non-virtual destructor signifies that deleting an instance of derived via a base pointer will not work. For example:

    class Base {};
    class Derived : public Base {};
    
    Base* b = new Derived;
    delete b; // Does not call Derived's destructor!
    

    If you don’t do delete in the above manner, then it will be fine. But if that’s the case, then you would probably be using composition and not inheritance.

    Will having a non-virtual destructor of a derived class act like a
    weak form of the Java final modifier?

    No, because virtual-ness propagates to derived classes.

    class Base
    {
    public:
        virtual ~Base() {}
        virtual void Foo() {};
    };
    
    class Derived : public Base
    {
    public:
        ~Derived() {}  // Will also be virtual
        void Foo() {}; // Will also be virtual
    };
    

    Here is the excerpt from the C++11 standard that formalizes this:

    […] If a class has a base class with a virtual destructor, its destructor (whether user- or implicitly- declared) is virtual.

    – [class.dtor] p9

    There isn’t a built-in language mechanism in C++03 or earlier to prevent subclasses(*). Which isn’t much of an issue anyway since you should always prefer composition over inheritance. That is, use inheritance when a "is-a" relationship makes more sense than a true "has-a" relationship.

    (*) ‘final’ modifier was introduced in C++11

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

Sidebar

Related Questions

Are there any circumstances in which Class.getDeclaringClass could give a different result from Class.getEnclosingClass
As a general rule, are there ever any circumstances in which it's acceptable for
Are there any circumstances under which a ThreadPoolExecutor.CallerRunsPolicy will throw a RejectedExecutionException ? It
Are there any circumstances where it is favourable to manually create a stub type,
Is there any way to trigger a function that's called when the user types
Is there any subprogram similar to DBMS_METADATA.GET_DDL that can actually export the table data
Is there any use cases for employing the Visitor Pattern in Scala? Should I
Is there any way to hover over an element that's already hidden. I am
Due to circumstances not fully under my control, I have to develop ACCESS queries
I have a c++ dll which I need to debug. Due to the circumstances

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.