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

  • Home
  • SEARCH
  • 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 7750879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:24:17+00:00 2026-06-01T11:24:17+00:00

This is a follow-up question to this one . Consider this example: #include <iostream>

  • 0

This is a follow-up question to this one.

Consider this example:

#include <iostream>

class A
{
};

class B : public A
{
    public:
    int i;
    virtual void Func() = 0;
};

class C : public B
{
    public:
    char c;
    void Func() {}
};

int main()
{
    C* pC = new C;
    A* pA = (A*)pC;
    std::cout << "pC == " << std::hex << pC << "\n";
    std::cout << "pA == " << std::hex << pA << "\n";
    return 0;
}

With Visual Studio 2010, the output is (on my machine):

pC == 002DEF90
pA == 002DEF94

(this is explained by the accepted answer of the question).

With g++, the output is:

pC == 0x96c8008
pA == 0x96c8008

So, the question is, how does the implementation of g++ handle this case? What makes the addresses the same when C should have a vtable? (I know that this is an implementation detail, don’t say that 🙂 I’m interested in this implementation detail out of curiosity).

  • 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-01T11:24:18+00:00Added an answer on June 1, 2026 at 11:24 am

    After much fiddling, I finally remembered something.

    The Empty Base Optimization.

    As soon as A gets a member, the result change. However as long as it has none, the compiler is not required to generate a real layout for A, all that matters is to guarantee that each A “object” will have a different address from any other A object.

    Therefore, the compiler simply use the address of the B subobject (which inherits from A) as a suitable address. And it turns out that B and C have the same address (first base + both having virtual methods).

    On the other hand, if A has a member OR if the first member of B is a A (there are other conditions), then the EBO cannot apply any longer and you’ll notice a jump in the addresses.

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

Sidebar

Related Questions

This is a follow-up questions on a previous one . Consider this code, which
This is a follow-on question from the one I asked here . Can constraints
This is like a follow-up question to this one . Basically what I'm doing
Just a follow up question to this one here => link Is it possible
I have a follow-up question to this one . I created a new form,
I have a follow up question to this one . Now that I have
This is really a follow on question to a previous one , where I
This question is a follow on from this one ... I am binding to
This is a follow up question to this one . I think I misunderstood
This a follow-up question to this one . Now I would like to convert

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.