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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:14:26+00:00 2026-05-20T02:14:26+00:00

I’ve been reading about this stuff that size of an object should be at

  • 0

I’ve been reading about this stuff that size of an object should be at least 1 byte (C++: What is the size of an object of an empty class?) and what’s wrong about having two empty objects the same address ? After all, we can have two pointers to the same object.

The googling tells me there is something about object identity fundemantal rule, but I can’t find more detailed info about that.

So… $SUBJ.

  • 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-20T02:14:27+00:00Added an answer on May 20, 2026 at 2:14 am

    Having two objects at the same address would mean that there would be no way to distinguish between these two objects when referencing them with pointers. For example, in the following code:

    EmptyClass o1;
    EmptyClass o2;
    
    EmptyClass * po = &o;
    po->foo();
    

    Should the foo method be called on o1 or o2?

    It could be argued that since these objects have no data and no virtual methods (otherwise they would have a non-zero size), it doesn’t matter on which instance the method is invoked. However, this becomes more important when we want to test if two objects are equal (i.e. if they are the same):

    template < typename T >
    bool isSame( T const & t1, T const & t2 )
    {
        return &t1 == &t2;
    }
    
    EmptyClass o1; // one object and...
    EmptyClass o2; // ...a distinct object...
    
    assert( ! isSame( o1, o2 ) ); // ...should not be one and same object!
    

    For a more concrete example, let’s assume that I want to associate some objects (I could say entities) with some values, let’s say in an associative container:

    Person you;
    Person me;
    
    // You and I are two different persons
    // (unless I have some dissociative identity disorder!)
    // Person is a class with entity semantics (there is only one 'me', I can't make
    // a copy of myself like I would do with integers or strings)
    
    std::map< Person *, std::string > personToName;
    
    personToName[&you] = "Andrew_Lvov";
    personToName[&me]  = "Luc Touraille";
    // Oh, bother! The program confused us to be the same person, so now you and I
    // have the same name!
    

    So yes, it all boils down to object identity: if objects were allowed to be empty, they could be deprived of their identity, which is simply not allowed by the language (thankfully).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.