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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:33:33+00:00 2026-05-23T14:33:33+00:00

I´m trying to accomplish the same which is described in a previous question: virtual

  • 0

I´m trying to accomplish the same which is described in a previous question:

virtual function call from base class

But, my real question is:

What if f() is the constructor in the Base class? Which g() will be called? I don´t know if I am doing wrong, but in my program it seems to be that is the opposite.

Taking the same variables from the previous question, a code which shows such

behavior would look like this:

Class Base

{   

    Base(){g();};

    virtual void g(){//Do some Base related code;}

};



Class Derived : public Base

{   

    Derived(){};

    virtual void g(){//Do some Derived related code};

};



int main()

{

    Derived newDerived;

    return 0;  

}

Update:

Thanx to Naveen.

He provided me a page which contains all related information about this topic.

I´ll let you know the link here:

parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.6

  • 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-23T14:33:33+00:00Added an answer on May 23, 2026 at 2:33 pm

    Even though it’s a virtual function, the base’s version will get called since the derived class isn’t fully constructed yet. The base class constructor is called before the derived class constructor, so if the derived virtual function were to get called, it would be with an incompletely-initialized instance – a possible (probably) recipe for disaster.

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

Sidebar

Related Questions

I'm trying to accomplish what is described here: http://sqldev.wordpress.com/2008/05/06/insert-into-temporary-table-from-stored-procedure/ The article says (with support
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
So I am trying to accomplish something like this: SELECT * FROM table WHERE
I'm trying to accomplish simply adding a css class to a div on alternate
Here's what I'm trying to accomplish: I need a button which is positioned a
In C++, I have an Object class, from which a number of other classes
I have been trying to accomplish the same as many frameworks do: having the
What I'm trying to accomplish My app generates some tabular data I want the
I am trying to accomplish something that seemed quite simple... I have 3 div
I'm trying to accomplish a simple task of creating a database with 2 tables

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.