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

  • Home
  • SEARCH
  • 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 6795451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:20:48+00:00 2026-05-26T18:20:48+00:00

I believe, a derived class can override only those functions which it inherited from

  • 0

I believe, a derived class can override only those functions which it inherited from the base class. Is my understanding correct.?

That is if base class has a public member function say, func, then the derived class can override the member function func.

But if the base class has a private member function say, foo, then the derived class cannot override the member function foo.

Am i right?

Edit

I have come up with a code sample after studying the answers given by SO members. I am mentioning the points which i studied as comments in the code. Hope i am right. Thanks

/* Points to ponder:
   1. Irrespective of the access specifier, the member functions can be override in base class.
      But we cannot directly access the overriden function. It has to be invoked using a public
      member function of base class.
   2. A base class pointer holding the derived class obj's address can access only those members which
      the derived class inherited from the base class. */

#include <iostream>

using namespace std;


class base
{
   private:
      virtual void do_op()
      {
         cout << "This is do_op() in base which is pvt\n";
      }

   public:
      void op()
      {
         do_op();
      }
};

class derived: public base
{
   public:
      void do_op()
      {
         cout << "This is do_op() in derived class\n";
      }
};

int main()
{
   base *bptr;
   derived d;

   bptr = &d;
   bptr->op(); /* Invoking the overriden do_op() of derived class through the public 
               function op() of base class */ 
   //bptr->do_op(); /* Error. bptr trying to access a member function which derived class 
                    did not inherit from base class */            

   return 0;
}
  • 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-26T18:20:49+00:00Added an answer on May 26, 2026 at 6:20 pm

    You can override functions regardless of access specifiers. That’s also the heart of the non-virtual interface idiom. The only requirement is of course that they are virtual.

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

Sidebar

Related Questions

A base class have readonly field of type List<SomeEnum> which the derived classes will
I understand that static_cast can convert between base and derived and between derived and
I want to compose application build version that is automatically derived from the Git
Given a base class where I have some logic that must run before and
I have a problem using a shared_ptr of a base class, I can't seem
Java and C# support the notion of classes that can't be used as base
I have a base class, Parameter, and two derived classes: Scalar & Vector. In
I have a superclass which instantiates my Sql class so all derived classes will
I have a sample program with a base Fruit class and a derived Apple
Q)is it a requirement that all interface classes inherit from super class? Q) In

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.