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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:03:10+00:00 2026-05-28T20:03:10+00:00

How to call base class method if it is not abstract. class WithAbstMethod {

  • 0

How to call base class method if it is not abstract.

class WithAbstMethod {
public:
    virtual void do() = 0;
}

class WithImplMethod : public WithAbstMethod {
public:
    virtual void do() {
        // do something
    }
}

template<typename BaseT>
class DerivedClass : BaseT {
public:
    virtual void do() {
        BaseT::do(); // here is a question. How to modify code, so that do() is called if it is not abstract?
        // do something
    }
}

void main() {
    DerivedClass<WithAbstMethod> d1;
    d1.do(); // only DerivedClass::do() should be called
    DerivedClass<WithImplMethod> d2;
    d2.do(); // both WithImplMethod::do() and DerivedClass::do() should be called
}

Is it possible to do this using templates in compile-time without much code (instantiate DerivedClass::do() method with BaseT::do() call and without depending on BaseT type)?
Obviously, provide implementation in WithAbstMethod class is not an option. Code above is pseudo-code so may contain minor errors.

  • 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-28T20:03:11+00:00Added an answer on May 28, 2026 at 8:03 pm

    Actually, providing an implementation for WithAbstMethod::do() might be an option. Abstract functions are allowed to have an implementation.

    void WithAbstMethod::do()
    {
        // do nothing...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a follwing class structure: public abstract class AbstractFoo { public virtual void
does anyone know a way to call a generic method of a base class
I cant call protected function in my base class. Why? It looks something like
I have defined an abstract method in my base class to take in a
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
I know that calling a virtual method from a base class constructor can be
I have an abstract Base class. Let's call it Animal::Base . module Animal class
class Program { static void Main(string[] args) { Foo.Calc(Foo); } } public abstract class
I've got an abstract class defined by another assembly (not editable): public abstract class
I have a bunch of classes extending an abstract Base class. Each subclass takes

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.