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#
  4. size of an object of a class

size of an object of a class

Scheduled Pinned Locked Moved C#
performancehelpquestion
4 Posts 2 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.
  • T Offline
    T Offline
    tina newcoder
    wrote on last edited by
    #1

    there is a class, say

    class a
    {
    int i,j,k;
    }

    then, another class is derived as,

    class b:a
    {
    int a,b,c;
    }

    now how many locations in the memory the object of class b will occupy, i mean wat will be the size of object of class b. 3 or 6 ??? i have tried to use sizeof operator. But the compiler is giving error !

    E 1 Reply Last reply
    0
    • T tina newcoder

      there is a class, say

      class a
      {
      int i,j,k;
      }

      then, another class is derived as,

      class b:a
      {
      int a,b,c;
      }

      now how many locations in the memory the object of class b will occupy, i mean wat will be the size of object of class b. 3 or 6 ??? i have tried to use sizeof operator. But the compiler is giving error !

      E Offline
      E Offline
      Eslam Afifi
      wrote on last edited by
      #2

      First, this code doesn't compile because you have a data member with the same name of the class "b" Second, I think you want to know how many data members are there in the class B. There are 6 data members i, j, k, a, b and c. But you can only access a, b and c from the class B because i, j and k are private members of the class "a". If you really want to know the size in bytes, http://blogs.msdn.com/cbrumme/archive/2003/04/15/51326.aspx[^] http://blogs.msdn.com/mab/archive/2006/04/24/582666.aspx[^]

      Eslam Afifi

      T 1 Reply Last reply
      0
      • E Eslam Afifi

        First, this code doesn't compile because you have a data member with the same name of the class "b" Second, I think you want to know how many data members are there in the class B. There are 6 data members i, j, k, a, b and c. But you can only access a, b and c from the class B because i, j and k are private members of the class "a". If you really want to know the size in bytes, http://blogs.msdn.com/cbrumme/archive/2003/04/15/51326.aspx[^] http://blogs.msdn.com/mab/archive/2006/04/24/582666.aspx[^]

        Eslam Afifi

        T Offline
        T Offline
        tina newcoder
        wrote on last edited by
        #3

        Thanx

        E 1 Reply Last reply
        0
        • T tina newcoder

          Thanx

          E Offline
          E Offline
          Eslam Afifi
          wrote on last edited by
          #4

          You're welcome.

          Eslam Afifi

          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