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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:37:06+00:00 2026-06-10T19:37:06+00:00

Possible Duplicate: Private virtual method in C++ If I understood correctly from this post

  • 0

Possible Duplicate:
Private virtual method in C++

If I understood correctly from this post (Private virtual method in C++), making a virtual function in a base class makes the derived classes able to override it. But it seems things stop there.

But if the base class virtual function is pure, that forces the derived classes to implement the function. Hence, a pure (public) virtual function is merely an interface. I can see a benefit here.

On the other hand, by making a base class virtual function private, only gives the derived class the ability to override the function, but I see no benefit of this. It’s as if that private virtual function is not even there. The derived class obviously does not know about the existence of that virtual function in base class because its private, so is there any benefit of declaring a base class private function virtual, in term of inheritance or polymorphism?

Also, is there any situation where a base class would declare a function ‘pure virtual’ and ‘private’?

Thank you.

  • 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-10T19:37:08+00:00Added an answer on June 10, 2026 at 7:37 pm

    One benefit is in implementing the template method pattern:

    class Base {
    
     public :
      void doSomething() {
        doSomething1();
        doSomething2();
        doSomething3();
      }
     private:
       virtual void doSomething1()=0;
       virtual void doSomething2()=0;
       virtual void doSomething3()=0;
    };
    
    
    class Derived : public Base {
      private:
       virtual void doSomething1() { ... }
       virtual void doSomething2() { .... }
       virtual void doSomething3() { .... }
    }
    

    This allows the derived classes to implement each piece of a certain logic, while the base class determines how to put these pieces together. And since the pieces don’t make sense by themselves, they are declared private and so hidden from client code.

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

Sidebar

Related Questions

Possible Duplicate: Why is it allowed to call derived class' private virtual method via
Possible Duplicate: Making a method private in a python subclass Private Variables and Methods
Possible Duplicate: JavaScript losing “this” object reference with private/public properties Why does the second
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Catching specific vs. generic exceptions in c# Here's an example method private
Possible Duplicate: Calling virtual functions inside constructors Look at this code. In the constructor
Possible Duplicate: Is Java pass-by-reference? I found an unusual Java method today: private void
Possible Duplicate: How to call base.base.method()? I have some trouble with Inheritance in C#.
Possible Duplicate: Best way to define private methods for a class in Objective-C Hi,
Possible Duplicate: Why are private virtual methods illegal in C#? I have the following

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.