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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:54:28+00:00 2026-06-06T01:54:28+00:00

I have a base class called Panel, where some information about a window is

  • 0

I have a base class called Panel, where some information about a window is stored, then, I have subclasses for all the controls: Button, Label etc. In the base class, I have the virtual void ApplySchemeSettings(Scheme* scheme) { } method, which is called within the Panel(Panel* parent) constructor. But instead of the subclass, the ApplySchemeSettings from the base class (Panel) is being called.

class Panel
{
    [...]

public:
    virtual void ApplySchemeSettings(Scheme* scheme) { };

    Panel(Panel* parent)
    {
        [...]

        this->ApplySchemeSettings(scheme());
    };
}

class Frame : public Panel
{
    [...]

public:
    void ApplySchemeSettings(Scheme* scheme)
    {
        this->border = scheme->GetBorder("FrameBorder");
    }
}

I can’t declare ApplySchemeSettings as abstract because the subclasses is made by user.

  • 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-06T01:54:29+00:00Added an answer on June 6, 2026 at 1:54 am

    Inside of a constructor, virtual functions don’t behave as you might expect. In particular, any call to a virtual function inside a constructor will always resolve the call to the version of the function declared inside the current class. The reason for this is that during object construction, a class is constructed by first having the most base class constructed, then its child class, then its child class, etc. Consequently, during object construction, the derived classes are not initialized until the base class constructors finish running. If you were to be able to call a virtual function and have it resolve to the most derived version inside of a base class constructor, you would be calling a method on a class that hadn’t yet been initialized at all – not even the default constructors for the data members would have been called yet.

    You will need to find some other approach to solving this problem. You might, for example, have a two-step construction in which you call some init() method after calling the constructor. However, there is no way to safely call the most derived version of a virtual function from the constructor.

    Hope this helps!

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

Sidebar

Related Questions

I have an abstract base class called Party. There are several concrete subclasses (Company,
I have a base-class called Element. Some other classes (like Label and Image) both
Basically I have a Base class called Program. I then have more specific program
I have a base class called Component. I also have 2 interfaces I2DComponent, and
Please Consider this scenario: We have a base class called clsMain : class clsMain
Let me explain you my situation. I have a base class called Shape, and
I have a class Contact (base class),a class called Customer and a class called
I have a base and derived class called Node which form elements of a
I have a base class with a property called Name, which has an XmlText
I have a table called Users ( class User < ActiveRecord::Base ) and a

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.