Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what is the size of a empty class?

what is the size of a empty class?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vikas amin
    wrote on last edited by
    #1

    What is the size of a empty class If the size of the class is zero what can be the problem with the class? Vikas Amin Embin Technology Bombay

    O L T D 4 Replies Last reply
    0
    • V vikas amin

      What is the size of a empty class If the size of the class is zero what can be the problem with the class? Vikas Amin Embin Technology Bombay

      O Offline
      O Offline
      Owner drawn
      wrote on last edited by
      #2

      vikas amin wrote:

      What is the size of a empty class

      1 or (>0)

      vikas amin wrote:

      If the size of the class is zero what can be the problem with the class?

      It cannot be zero.

      Jesus Loves:rose:

      --Owner Drawn:rose: --Defeat is temporary but surrender is permanent --Jesus is Lord:rose:

      1 Reply Last reply
      0
      • V vikas amin

        What is the size of a empty class If the size of the class is zero what can be the problem with the class? Vikas Amin Embin Technology Bombay

        L Offline
        L Offline
        Laxman9
        wrote on last edited by
        #3

        first thing... The size of the empty class is 1 if it doesn't contains any member variables else its size is the total bytes required for the variables in that class. second thing... if the class contains atleast one virtual function then its size is 2 bytes without member variables as the object of the class contains the address of the VTABLE. for the existance of the object the class having minimum 1 byte size. Thanks and Regards Laxman FAILURE is the first step towards SUCCESS :cool:

        V 1 Reply Last reply
        0
        • L Laxman9

          first thing... The size of the empty class is 1 if it doesn't contains any member variables else its size is the total bytes required for the variables in that class. second thing... if the class contains atleast one virtual function then its size is 2 bytes without member variables as the object of the class contains the address of the VTABLE. for the existance of the object the class having minimum 1 byte size. Thanks and Regards Laxman FAILURE is the first step towards SUCCESS :cool:

          V Offline
          V Offline
          vikas amin
          wrote on last edited by
          #4

          Yeh i checked it IDE but the question is why ? For a class containing only one "char" variable the size of the class is 1 . how??? even if the class is empty its 1 and even if it has a character variable its one? Vikas Amin Embin Technology Bombay

          L 1 Reply Last reply
          0
          • V vikas amin

            What is the size of a empty class If the size of the class is zero what can be the problem with the class? Vikas Amin Embin Technology Bombay

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            class A {} a;
            sizeof(a);


            TOXCCT >>> GEII power
            [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

            1 Reply Last reply
            0
            • V vikas amin

              Yeh i checked it IDE but the question is why ? For a class containing only one "char" variable the size of the class is 1 . how??? even if the class is empty its 1 and even if it has a character variable its one? Vikas Amin Embin Technology Bombay

              L Offline
              L Offline
              Laxman9
              wrote on last edited by
              #6

              that is the trick if class contains any variable the size of the class is the summation of bytes of member variables and if no variables then it's size is 1 byte. and as we know that minimum variable size is 1 byte and those for char variables. Thanks and Regards Laxman FAILURE is the first step towards SUCCESS :cool:

              1 Reply Last reply
              0
              • V vikas amin

                What is the size of a empty class If the size of the class is zero what can be the problem with the class? Vikas Amin Embin Technology Bombay

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                The size of an empty class is non-zero. Otherwise, two empty classes of the same type would have the same address.


                "The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups