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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:00:40+00:00 2026-05-21T21:00:40+00:00

I am a beginner of C++, I am studying virtual functions these days. There

  • 0

I am a beginner of C++, I am studying virtual functions these days.
There are some questions confuse me a lot.

for example:

class A {
  public:
  virtual void f() {
      //do something; 
  }
}

class B: public A {
   public:
   virtual void f() {
//do something;
}
}
  1. class A contains a virtual function f(), and class B inherits it. Inside class B, the function f() is also declared as virtual, so does this mean f() in class B overloads f() in class A? Does it allow classes which inherit B to overload f()? Or does B define a new virtual function which is different from f() in class A?

  2. Virtual functions provide a way of overloading methods. If B inherits A and does not declare the f() as virtual, then can a class C which inherits B overload the f() and achieve polymorphism?

  • 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-21T21:00:40+00:00Added an answer on May 21, 2026 at 9:00 pm

    inside class B, the function f() also be declared as virtual, so does this mean f() in class B overload f() in class A

    No, it doesn’t overload. It overrides. Also the keyword virtual is optional in class B. B::f() will always be a virtual function, whether you write virtual or not.

    The term overload is used when you define a function with same name but different parameter(s). In your case, the signature of the function f is exactly same in both classes, that means it isn’t overloading; the derived class basically overrides the base class definition of f().

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

Sidebar

Related Questions

Beginner question. How come I can do this: Public Class Form1 Private StudentsInMyRoom As
I'm trying to do something with javascript (I'm a beginner and I'm studying it)
Beginner help needed :) I am doign an example form a php book which
Beginner here See - http://www.w3schools.com/js/tryit.asp?filename=try_dom_tablerow_cells In this example, when change content is pressed, new
VS beginner question. How to change parent control of a control? Example. I have
Python beginner here. I've looked around and found similar questions but can't quite cobble
For a beginner, which is the best book to start with for studying Bayesian
I am studying 'Web Service' this week and found good tutorial and example code.
Beginner Question. Below is an example given on the Cradle CouchDB documentation: https://github.com/cloudhead/cradle What
I am a beginner Flash developer. I saw some site like [ http://www.3dfreeair.com] 1

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.