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

  • Home
  • SEARCH
  • 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 3973906
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:30:20+00:00 2026-05-20T04:30:20+00:00

class base { public: virtual void start(); virtual void stop(); void doSomething() { start();

  • 0
class base
{
  public:
  virtual void start();
  virtual void stop();

  void doSomething() { start(); .... stop(); }
}

class derived : public base
{
  public:
   void start();
   void stop();
}

But when I call doSomething() in the derived class it is using it’s own definition of Start() and Stop() – not the derived ones.

I don’t want to rewrite doSomething() in the derived class because it would be identical to the base one. What am I doing wrong?

Sorry if that wasn’t clear.
The behaviour of Start() and Stop() in the derived class is different (it’s a different machine) – but I want to use the original base class doSomething() because that hasn’t changed. It just has to start() and stop() using the new derived class code.

  • 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-20T04:30:21+00:00Added an answer on May 20, 2026 at 4:30 am

    The code you’ve posted should work the way you want. Calling doSomething on an instance of derived will call the overridden start and stop functions defined in derived.

    There’s an exception to that, though. If you call doSomething in the constructor or destructor of base (whether directly or indirectly), then the versions of start and stop that get called will be the ones defined in base. That’s because in those circumstances, you don’t actually have a valid derived instance yet. It’s either not fully constructed or partially destructed, so the language prevents you from calling methods that would use the partial object.

    If you’re not calling it from a base constructor or destructor, then there is more to the problem than what’s shown here.

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

Sidebar

Related Questions

Suppose I have a base and derived class: class Base { public: virtual void
#include<iostream> using namespace std; class base { public: virtual void add() { cout <<
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual
Given the following snippet, class Base { public: virtual void eval() const { std::cout<<Base
#include<iostream> using namespace std; class Abs { public: virtual void hi()=0; }; class B:public
If I have a base class: class Base { public: virtual void Test()=0; };
I have these classes: class Base { public: virtual void foo(int x = 0)
I have following situation class base { public: virtual void Accepted(SOCKET s) //// Event
#include <iostream> class base { public: virtual void print (int a) { std::cout <<
consider the following program: class Base { public: virtual void foo() const { cout

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.