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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:37:43+00:00 2026-06-03T20:37:43+00:00

I am making a class which inherits off another and must return the value

  • 0

I am making a class which inherits off another and must return the value of a function in the base class… It is confusing so I will let the code speak for itself…

class ParentClass {
public:
    virtual bool getMyVal();
};

bool ParentClass::getMyVal() {
    return true;   // in my program there is a bit more to it
}

class ChildClass : public ParentClass {
public:
    bool getMyVal();
};

bool ChildClass::getMyVal() {
    CalculateMassOfSun();

    return parent::getMyVal();    // Please make sure you read below...
}

So this is just an example of what I want to do, not the actual code. As you can see, in ChildClass::getMyVal(), is basically needs to do some pre-computation then run the same function in the parent class and return its value. I know that it is a virtual function in the parent, and that I have not gone about invoking the function in the parent the right way – it is how it is done in PHP and the only way I can think of that makes sense to me and hopefully others at the moment.

So how would I go about doing this? At the moment, I have found something along the lines of:

bool ChildClass::getMyVal() : /*ParentClass::*/getMyVal() { ... }

however it does not return the value here.

Thanks in advance for your responses.

  • 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-03T20:37:45+00:00Added an answer on June 3, 2026 at 8:37 pm

    To invoke the base definition of getMyVal just prefix the call with the base type name

    return ParentClass::getMyVal();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Message model class (which inherits from ActiveRecord::Base). For a particular deployment,
Right now I have a base class for my pages which inherits System.Web.UI.Page and
I am having a little design crisis, I am making a Plane class, which
I am making a card game in ruby. I have the Game class, which
So, I have a base class which has a private locking object like so:
and i'm making a 'Body' class which holds a bunch of 2D shapes together
I am making a multithreaded pacman game. There is a PacmanController class which extends
I have a class which i realized will not always correctly instantiate and as
I have a class for logging, which MUST NOT inherit std::ostream, and has operator<<
I have a abstract class which represents an immutable value. Like strings, the immutable

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.