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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:14:25+00:00 2026-06-03T00:14:25+00:00

Possible Duplicate: How to force child same virtual function call its parent virtual function

  • 0

Possible Duplicate:
How to force child same virtual function call its parent virtual function first

I have a class hierarchy where each derived class overrides a given virtual function and starts its implementation by calling the one in its parent class. The goal is to have each of the derived implementation to be executed, but I do not like the way I do it.

For example, I have this class:

class base
{
public:
  void do_stuff() { do_something(); }
  virtual void do_something() { }
};

Then I derive this class on several levels:

class derived_10:
  public derived_9 // which inherit from derived_8 and so on until derived_0
                   // which inherit from base
{
public:
  virtual void do_something()
  {
    // this will also call derived_8::do_something() and so on
    // until base::do_something()
    derived_9::do_something();

    // then, some stuff
  }
};

I’m looking for a solution that will make sure that all derived_x::do_something() will be called in sequence when base::do_stuff() is called, without having to expect the derived classes to do this themselves. Do you have an idea of the best way to get this behavior ?

  • 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-03T00:14:26+00:00Added an answer on June 3, 2026 at 12:14 am

    I’ve already asked a very similar question before: Calling overriden class methods as a chain in C++

    The answer I’ve accepted pointed at your own solution. I can give you an idea about an alternative though. Constructors and destructors already have this behavior in C++, you might want to consider restructuring your code, so that the work is done during the construction or the destruction of an object that belongs to a class in a hierarchy. I’m not sure you’ll be able to make this worth the effort though. On the other hand, you never know what you can get out of some template metaprogramming + some preprocessor magic.

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

Sidebar

Related Questions

Possible Duplicate: How to force child same virtual function call its parent virtual function
Possible Duplicate: Force Download an Image Using Javascript Basically I want to have the
Possible Duplicate: Timeout on a Python function call I want to implement that when
Possible Duplicate: jquery: how to force a pdf download automatically? Afternoon folks, I have
Possible Duplicate: Passing a Int value to another class I have been trying to
Possible Duplicate: css rule to disable text selection highlighting On my homepage i have
Possible Duplicate: Symfony2 AJAX Login I have implemented a custom authentication handler service to
Possible duplicate: why does the css min-width attribute not force a div to hae
Possible Duplicate: Referring to a static member of a subclass Please have a look
Possible Duplicate: How to force C# App to run as administrator on Windows 7

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.