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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:14:32+00:00 2026-05-16T14:14:32+00:00

Is it possible to make my member functions final as in Java, so that

  • 0

Is it possible to make my member functions final as in Java, so that the derived classes can not override them?

  • 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-16T14:14:33+00:00Added an answer on May 16, 2026 at 2:14 pm

    It is so much possible that it is in fact the default behaviour. I.e. if you don’t declare your class instance methods explicitly as virtual, they can’t be overridden in subclasses (only hidden, which is a different – and almost always erroneous – case).

    Effective C++ Third Edition, Item 36 deals with this in detail. Consider

    class B {
    public:
      virtual void vf();
      void mf();
      virtual void mf(int);
      ...
    };
    
    class D: public B {
    public:
      virtual void vf();              // overrides B::vf
      void mf();                      // hides B::mf; see Item33
      ...
    };
    
    D x;                              // x is an object of type D
    B *pB = &x;                       // get pointer to x
    D *pD = &x;                       // get pointer to x
    
    pD->vf();                         // calls D::mf, as expected
    pB->vf();                         // calls D::mf, as expected
    pD->mf();                         // calls D::mf, as expected
    pB->mf();                         // calls B::mf - surprise!
    pD->mf(1);                        // error -  D::mf() hides B::mf(int)!
    pB->mf(1);                        // calls B::mf(int)
    

    So this is not exactly how final behaves in Java, but you can only get this close with C++. An alternative might be to prevent subclassing altogether. The technical – working, but not nice – solution to this is to declare all your constructors private (and provide a static factory method if you want to allow instantiation of your class, of course).

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

Sidebar

Related Questions

Is it possible make some handler that will do something when user shutdown computer
Is it possible make an activity, that will lock the android device? That device
To make a struct's members private to the outside I know that I can
I am attempting to make a class that has a template object member inside
One of my WCF functions returns an object that has a member variable of
Is it possible to make a C++ header file (.h) that declares a class,
Possible Duplicate: Make error: missing separator I am so stressed out by this silly
Possible Duplicate: Make iPhone app paid version replace free version on install from app
is possible to make own help message or attach own event on help option
Is it possible to make a line move between links when the mouse is

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.