Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10778

sizeof class

From asit <lipun4u@gmail.com>
Newsgroups comp.lang.c++
Subject sizeof class
Date 2011-10-10 11:22 -0700
Organization http://groups.google.com
Message-ID <21470027.1607.1318270963966.JavaMail.geo-discussion-forums@prdw1> (permalink)

Show all headers | View raw


Please go through the following code...


#include <iostream>

using namespace std;

class Empty {};

class Derived1 : public Empty {};

class Derived2 : virtual public Empty {};

class Derived3 : public Empty
{
        char c;
};

class Derived4 : virtual public Empty
{
        char c;
};

class Dummy
{
        char c;
};

int main()
{
        cout<<"Sizeof(Empty) : "<<sizeof(Empty)<<endl;
        cout<<"Sizeof(Derived1) : "<<sizeof(Derived1)<<endl;
        cout<<"Sizeof(Derived2) : "<<sizeof(Derived2)<<endl;
        cout<<"Sizeof(Derived3) : "<<sizeof(Derived3)<<endl;
        cout<<"Sizeof(Derived4) : "<<sizeof(Derived4)<<endl;
        cout<<"Sizeof(Dummy) : "<<sizeof(Dummy)<<endl;

        return 0;
}


Why sizeof Derived4 is 8 bytes ?

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

sizeof class asit <lipun4u@gmail.com> - 2011-10-10 11:22 -0700
  Re: sizeof class Gerald Breuer <Gerald.Breuer@googlemail.com> - 2011-10-10 20:30 +0200
    Re: sizeof class asit <lipun4u@gmail.com> - 2011-10-10 12:13 -0700
      Re: sizeof class Ian Collins <ian-news@hotmail.com> - 2011-10-11 08:23 +1300
        Re: sizeof class Victor Bazarov <v.bazarov@comcast.invalid> - 2011-10-10 15:28 -0400
      Re: sizeof class Gerald Breuer <Gerald.Breuer@Use-Author-Supplied-Address.invalid> - 2011-10-10 22:25 +0200
      Re: sizeof class Markus Wichmann <nullplan@gmx.net> - 2011-10-10 22:48 +0200

csiph-web