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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:10:59+00:00 2026-06-03T22:10:59+00:00

Edit Solved and Reposted as sample program The scenario was as follows: The class

  • 0

Edit Solved and Reposted as sample program

The scenario was as follows:

The class hierarchy:

class Base
{
public:
   virtual void output() = 0;
private:
   int a;
};

class Derived_1 : public Base
{
public:
   virtual void output()
   {
      cout << "Derived_1" << endl;
   }
};

class Derived_2 : public Derived_1
{
public:
   virtual void output()
   {
      cout << "Derived_2" << endl;
   }
};

The implementation:

Derived_2* obj = reinterpret_cast<Derived_2*>(new Derived_1());
obj->output();

This will output “Derived_1” and not “Derived_2”. I’m sure this is nothing new to most of you, but it was something I didn’t think about when making some of my factory functions in my application.

  • 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-03T22:11:02+00:00Added an answer on June 3, 2026 at 10:11 pm

    You are allocating a Value_object_data object, not Value_object_uint32. The fact that you’re casting it as a Value_object_uint32 changes nothing. The actual object’s virtual table has no knowledge of Value_object_uint32; in its virtual function table, which is constructed at the time of err… construction, format points to Value_object_data‘s format. Strong-arming the type of pointer which points to the actual object does nothing to fix the situation.

    Constructors for all base and inherited classes in a given hierarchy are called from the most derived to the root, exactly once for each class. This means, you don’t have to explicitly call the base class constructor. It will be called automatically. If you need to specify which of several base class constructors should be used you can do that too:

    class Base
    {
    public:
        Base() {} // default constructor
        Base(int a) {}
    };
    
    class Derived
    {
    public:
        Derived() : Base()
        {
        }
    
        Derived(int a)
          : Base(a) // Select the Base ctor that takes an int, instead of the default
        {
        }
    };
    
    int main()
    {
        Derived d1;    // Calls Derived() and Base() ctors in this order
        Derived d2(5); // Calls Derived(5) and Base(5) in this order
    }
    

    Of course, the Derived(int a) constructor is not required to call the Base(int) constructor. In this case the Base() constructor will be called automatically.

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

Sidebar

Related Questions

Edit: Solved, I wasn't using 'validate()' after adding components. I have a GUI class
EDIT SOLVED The code <?php ob_start(); ?> put before any other output seemed to
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to
edit: Solved - mod_rewrite was the problem I can't get CI to work as
EDIT: SOLVED Thanks Brooks. Your question led me to keep digging into if the
EDIT: solved it, turns out I should use %c not %s because foodSelect and
[EDIT: Problem solved. Please see my answer below.] In my app I call the
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
Edit 4/4/12 I STILL HAVE ONE QUESTION: I solved my issue but it adds

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.