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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:29:45+00:00 2026-06-12T03:29:45+00:00

For example, I have the base class with pure virtual functions: class IBase {

  • 0

For example, I have the base class with pure virtual functions:

class IBase
{
    virtual void Function(const IBase& ref) = 0;
};

If I inheriet the class, do I have to overload ‘Function’ which takes the derived class as a parameter?

class Derived
{
    // this will be implemented
    virtual void Function(const IBase& ref) {}

    // does this have to be implemented
    virtual void Function(const Derived& ref) {}
};

Or can the compiler differentiate between the calls and I can skip writing the overload function?

Derived d();
...

IBase* dptr = &d; // ignoring cast for example

// would never really call 'Function' on itself, this is for example purposes
dptr->Function(d);

Notes: IBase::Function must take reference type, not pointer type.

I understand the rules of inheriting pure-virtual functions, just not this special case where the pure virtual function takes the base type as a parameter.

What I need to know is do I have to implement an overload in each inherited type that takes the inherited type as a parameter, or will the compiler understand that if I pass a Derived reference, to call on the virtual implementation?

  • 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-12T03:29:46+00:00Added an answer on June 12, 2026 at 3:29 am

    Yes, if you have a Function(const IBase&) in the base class and override it in the derived class, you can pass references to the derived class to Function and the Function(const IBase&) will be called.

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

Sidebar

Related Questions

Basically, I have a pure virtual class Base, and a concrete class Derived which
I have an abstract class defining a pure virtual method in c++: class Base
i have a Base class and Derived class. they have a virtual function- virtual
I have a base class and it has virtual functions. The issue is that,
For example: I have an implementation (say doSomething()) in Base class. I want all
I have a model, for example : class Account < ActiveRecord::Base before_create :build_dependencies def
I have base class (virtual), with some children, and an array with pointers on
So say, for example I have two classes: Base = declarative_base() class Vendor(Base): __tablename__
I have one base class which holds a map for function pointers like this
For example, I have a base class and a derived class: >>> class Base:

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.