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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:29:38+00:00 2026-05-31T20:29:38+00:00

I have a function X() declared as PURE VIRTUAL in base class: class Base

  • 0

I have a function X() declared as PURE VIRTUAL in base class:

class Base 
{
public:  
    virtual HRESULT X()=0; // Now it's pure virtual. 
    .......
    };




class Derived_1 : public Base  
  {   
    HRESULT X()   
    {  
    // body of function X() ; full definition given here as per Derived_1's context. SHOULD WE MAKE THIS VIRTUAL?                                                     
    }

    ..................              

  };            

class Derived_2 :public Base             
   {          
    HRESULT X()            
         {             
        // body of function X() ; full definition given here Derived_2's context.  SHOULD WE MAKE THIS VIRTUAL?
        }              
         ..................           
   };

If our intention is to call the function X() generically using a base class pointer, so the decision wheather Derived_1’s or Derived_2’s definition of X() is called, then is it necessary to make the X() in Derived classes Virtual too.

Base * bPtr;
bPtr = new Derived_1(); OR bPtr = new Derived_2(); (Dynamic decision)
bPtr->X()

I feel there is no need to attach the virtual keyword to the definition in Derived classes. Am I right?

Thanks in advance.

  • 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-31T20:29:39+00:00Added an answer on May 31, 2026 at 8:29 pm

    The functions in the derived classes will automatically be virtual if the signature of the function (the type of the arguments and return value, identifiers such as const and virtual) in the derived class is identical to the one in your base class. It doesn’t matter whether it is virtual or pure virtual.

    So in your example it is not necessary to add virtual for the derived classes.

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

Sidebar

Related Questions

I have a function declared in my base class and specified as virtual, I
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
Do you have to declare methods replacing a pure virtual function in a base
Given the base class A and the derived class B: class A { public:
I have two header files A.h(include a pure virtual function) and B.h. A.h :
For example i have function declared in AS3.0 class: private function log():void{ // working
I have a class function (declared and implemented) in a class MyUtils. When I
In my main class 'A' I have declared a function and delegate to call
I have defined an interface in C++, i.e. a class containing only pure virtual
If I have a function declared as such: public static void main(String[] args){ blahblahlbah;

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.