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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:16:33+00:00 2026-05-27T21:16:33+00:00

I am not 100% sure the outcome that would occur in my current setup

  • 0

I am not 100% sure the outcome that would occur in my current setup up.

This maybe a stupid question, but I can not see a similar example.

Here is the example code

Class A {

  public:
    virtual Steer* getSomeParticularInfo(){ return m_steer; }

  private:
    Steer* m_steer:
}


Class B: A {

  public:
    virtual Steer* getSomeParticularInfo(){ return m_steer; }

  private:
    Steer* m_steer:
}

Class C: B {

  public:
    //Does not have its own getSomeParticularInfo() member function

  private:
    Steer* m_steer:
}

My question:

If I call getSomeParticularInfo. Will it come from Class B because it is the most recent derived class or does it come from the base class?

//Inside Class C constructor
C::C(){
  m_steer = getSomeParticularInfo();
}
  • 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-27T21:16:33+00:00Added an answer on May 27, 2026 at 9:16 pm

    In order to understand this you need to understand the order of constructors here. Before the body of C::C() is executed the constructor for the base type is executed. In this case B::B(). This is a recursive process so what you end up with is the constructors for A, B and C executing in order.

    The constructor of a type in C++ will change the virtual method table to point to the version of a virtual method / override that it defines. Hence

    • A::A() will set the entry of getSomeParticularInfo to A::getSomeParticularInfo
    • B::B() will set the entry of getSomeParticularInfo to B::getSomeParticularInfo

    At the point C::C() has run both the constructor for A and B have run in that order. Hence any calls to getSomeParticularInfo will resolve to B::getSomeParticularInfo

    Note: In general I would avoid using virtual methods in the constructor. It’s generally speaking a bad practice because of the potential for confusion it creates.

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

Sidebar

Related Questions

I'm not 100% sure that this is an appropriate question for SO but here
I'm not 100% sure how I should word this question but I'll try my
Not 100% sure how to frame this question but here goes... I currently work
This might not be a Microsft.Practices specific question (probably not but not 100% sure)
I'm not 100% convinced that this is a good idea, but I bumped into
I'm not 100% sure it wasn't always this way and I never noticed... but
I'm not 100% sure I'm doing this right, but I think I've found an
This sounds daft and easy but I'm not 100% sure here. I have this
I am not 100% sure whether this is a Django or a Python question,
I could probably go benchmark this myself but I'm not 100% sure how to

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.