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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:40:06+00:00 2026-05-14T00:40:06+00:00

The size of a class with no data members is returned as 1 byte,

  • 0

The size of a class with no data members is returned as 1 byte, even though there is an implicit ‘this’ pointer declared. Shouldn’t the size returned be 4 bytes(on a 32 bit machine)? I came across articles which indicated that ‘this’ pointer is not counted for calculating the size of the object. But I am unable to understand the reason for this.
Also, if any member function is declared virtual, the size of the class is now returned as 4 bytes. This means that the vptr is counted for calculating the size of the object. Why is the vptr considered and ‘this’ pointer ignored for calculating the size of object?

  • 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-05-14T00:40:06+00:00Added an answer on May 14, 2026 at 12:40 am

    The this pointer is not a member of the class. It’s just a construct that is used in methods belonging to the class to refer to the current instance.

    If you have a class like this:

    class IntPair
    {
    public:
      IntPair(int a, int b) : _a(a), _b(b) { }
    
      int sum() const { return _a + _b; }
    
    public:
      int _a;
      int _b;
    };
    

    This class only needs space for two instances of int for each instance. Once you’ve created an instance and are running the sum() method, that method is called with a pointer to the instance, but that pointer always comes from somewhere else, it isn’t stored in the object instance.

    For example:

    IntPair *fib12 = new IntPair(89, 144);
    
    cout << fib12->sum();
    

    Notice how the variable that becomes the this pointer is stored outside the object, in the scope that created it.

    You could, in fact, always transform a method like the one above into:

    static int sum2(const IntPair* instance)
    {
      return instance->_a + instance->_b;
    }
    

    If the above is defined inside the class (so it can access the private members), there’s no difference. In fact, this is how methods are implemented behind the scene; the this pointer is just a hidden argument to all member methods.

    The call would become:

    IntPair* fib12 = new IntPair(89, 144);
    
    cout << IntPair::sum2(fib12);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get the actual size of a class instance in
Is there any way to get the size of an instance (or the class
In C++ is always better to keep data of a class as private members.
Let's say I have a Size class which has height and width properties (in
I have a .txt file like: Symbols from __ctype_tab.o: Name Value Class Type Size
class Ball: a = [] def __init__(self): pass def add(self,thing): self.a.append(thing) def size(self): print
I resized the picture into 100x100 size by using Graphics class and drawImage() method.
How can I find the size of an abstract class? class A { virtual
Possible Duplicate: C++: What is the size of an object of an empty class?
println args println args.size() println args.each{arg-> println arg} println args.class if (args.contains(Hello)) println Found

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.