+ Reply to Thread
Results 1 to 2 of 2

Thread: What is the size of an Empty class in C++?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    29

    What is the size of an Empty class in C++?

    Hi All,

    What is the size of an Empty class in C++? Can anyone help by providing an example?

    Thanks,
    Tiger

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    Hi Tiger,

    Code:
    class CEmptyClass
    {
    } ;
    
    void UseEmptyClass()
    {
    	//Hummm, nSize is not Zero! But why?
    	int nSize = sizeof(CEmptyClass) ;
    
    
    	CEmptyClass objEmptyClass1 ;
    	CEmptyClass objEmptyClass2 ;
    
    	//What would you excpet for this? these objects should not be same! Right?
    	if (&objEmptyClass1 == &objEmptyClass2)
    	{
    		printf("objEmptyClass1 is same as object objEmptyClass2") ;
    	}
    	else
    	{
    		printf("objEmptyClass1 is diferent than object objEmptyClass2") ;
    	}
    }
    Notes:
    Empty Class size can be compiler dependent.

    Hope this helps you.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts