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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:38:31+00:00 2026-06-19T03:38:31+00:00

I am new to C++ programming, in the below code i am using virtual

  • 0

I am new to C++ programming, in the below code i am using virtual inheritance so size of derived class is showing 24 bytes but i am not getting how it is so please help me how exactly it is.

#include "stdafx.h"
#include <iostream>
using namespace std;

class BaseClass
{
      private : int a, b;
      public :
  BaseClass()
  {
    a = 10;
    b = 20;
  }
  virtual int area()
  {
    return 0;
  }
};

class DerivedClass1 : virtual public BaseClass
{
  int x;
      public:
  virtual void simple()
  {
    cout << "inside simple" << endl;
  }
};

int main()
{
   DerivedClass1 Obj;
   cout << sizeof(Obj) << endl;
   return 0;
}
  • 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-19T03:38:32+00:00Added an answer on June 19, 2026 at 3:38 am

    I guess that you’re compiling as 64-bit? In that case, your DerivedClass1 will probably be laid out in memory with this arrangement of bytes:

    offset     size    type
    0          8       pointer to virtual function table
    8          4       int BaseClass::a
    12         4       int BaseClass::b
    16         4       int DerivedClass1::x
    20         4       filler, so that the total size of this class is an even number of 64-bit (8-byte) words
    

    The pointer to virtual function table is silently added to your class by the C++ compiler for any class that is part of a class inheritance hierarchy containing any virtual functions.

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

Sidebar

Related Questions

I am new to cocoa programming, Using the below code I want to show
Pardon my ignorance, I'm new to Ruby, but not programming. I'm using a gem
I'm a c# SQL Server developer new to Oracle programming . The code below
Screenshot: I populated the above menu in screenshot using below code, but silly me
I'm getting a syntax error while using the code below. it suppoused to avoid
I am using c# for programming! Below is my aspx code where I am
I am new in C programming, and trying to create simple code below for
I'm new to programming and am taking a C# class. I am getting compiler
New to programming. I wrote a Python code (with help from stackoverflow) to read
Hi there I am new to C programming and have been using Xcode 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.