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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:04:37+00:00 2026-05-11T03:04:37+00:00

Is there is any reason to make the permissions on an overridden C++ virtual

  • 0

Is there is any reason to make the permissions on an overridden C++ virtual function different from the base class? Is there any danger in doing so?

For example:

class base {     public:         virtual int foo(double) = 0; }  class child : public base {     private:         virtual int foo(double); } 

The C++ faq says that it is a bad idea, but doesn’t say why.

I have seen this idiom in some code and I believe that the author was attempting to make the class final, based on an assumption that it is not possible to override a private member function. However, This article shows an example of overriding private functions. Of course another part of the C++ faq recommends against doing so.

My concrete questions:

  1. Is there any technical problem with using a different permission for virtual methods in derived classes vs base class?

  2. Is there any legitimate reason to do so?

  • 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. 2026-05-11T03:04:37+00:00Added an answer on May 11, 2026 at 3:04 am

    The problem is that the Base class methods are its way of declaring its interface. It is, in essence saying, ‘These are the things you can do to objects of this class.’

    When in a Derived class you make something the Base had declared as public private, you are taking something away. Now, even though a Derived object ‘is-a’ Base object, something that you should be able to do to a Base class object you cannot do to a Derived class object, breaking the Liskov Substitution Prinicple

    Will this cause a ‘technical’ problem in your program? Maybe not. But it will probably mean object of your classes won’t behave in a way your users expect them to behave.

    If you find yourself in the situation where this is what you want (except in the case of a deprecated method referred to in another answer), chances are you have an inheritance model where inheritance isn’t really modeling ‘is-a,’ (e.g. Scott Myers’s example Square inheriting from Rectangle, but you can’t change a Square’s width independent of its height like you can for a rectangle) and you may need to reconsider your class relationships.

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

Sidebar

Related Questions

Is there any real reason not to make a member function virtual in C++?
Is there any reason that will make you use: add2 = lambda n: n+2
When designing a collection class, is there any reason not to implement locking privately
In ASP.NET, is there any reason not to make a set of functions that
Is there any reason this doesn't work? / Any way to make it work?
Is there any reason why I should close the connection after a query or
Is there any reason why this shouldn't work? [PseudoCode] main() { for (int i
Is there any reason why images are not being displayed if I place it
Is there any reason to use Spring MVC (or other similar frameworks) as a
Is there any reason to do use block initialization, like this: x = Observer.new

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.