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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:44:15+00:00 2026-06-04T23:44:15+00:00

I have a class ‘base’ with a virtual destructor and thus a VTable and

  • 0

I have a class ‘base’ with a virtual destructor and thus a VTable and corresponding VTPR in it, and a class derived from it:

class base {
public:
    virtual ~base() {}
};

class der : base {};

main()
{

    int a = sizeof(base); // = 4 , fine !

    int b = sizeof(der);  // = 4 too ?
}

Now as derived class too is virtual, it’ll have a VPTR of its own, but since it also has a subobject of the base class with a VPTR in it, shouldn’t the size of the class ‘der’ be 8 bytes i.e. the size of the VPTR of the class ‘der’ + size of VPTR of the subobject of class ‘base’? (when sizeof(void*) = 4 bytes ).

So basically my question is : When the subobject of class ‘base’ is made in ‘der’ does it have a seperate new VPTR ? And if it is so then why its size is not getting added while calculating the size of ‘der’?

Can somebody please clarify this.

  • 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-04T23:44:17+00:00Added an answer on June 4, 2026 at 11:44 pm

    This is all implementation-specific. But in practice, there will only be one vptr in the derived class; there is no need for two. The whole point of the vptr is it’s what gets used to dynamically call the correct override of the virtual function; der objects will simply have a different pointer value to base objects.

    [Note: Your example is probably confused by the fact that you are (unintentionally?) using private inheritance, rather than the more typical public inheritance…]

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

Sidebar

Related Questions

I have: class BASE{ public: virtual void func1() = 0; }; Then I have
I have class A and B which inherit from Base. Base has a private
I have class A: public class ClassA<T> Class B derives from A: public class
I have class A derived from a Windows.Form class, using the VS2008 designer. When
I have class Question < ActiveRecord::Base has_many :tasks, :as => :task end class QuestionPlayer
I have class class User extends BaseModel{ public $id; public $name; } class BaseModel{
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
I have class MyContainer < ActiveRecord::Base :has_many MyObjects, :dependent => :destroy end I want
I have class like public class ProgressBars { public ProgressBars() { } private Int32
I have: class A { public: B toCPD() const; And: template<typename T> class Ev

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.