tell me why the output is this????

This is a discussion on tell me why the output is this???? within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream.h> #include<conio.h> class A { private : int a; }; class B : private A { }; class C ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    Bangalore,INDIA
    Posts
    14

    Question tell me why the output is this????

    Code:
    #include<iostream.h>
    #include<conio.h>
    
    class A
    {
      private :
      int a;
    };
    class B : private A
     {
     };
    class C : private B
     {
     };
    
    void main()
      {
         C c;
         cout<<sizeof(c);
         getch();
      }
    
    
    OUTPUT
    2
    raj.knd@gmail.com

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    R u working on Turbo C on Microsoft Windows ????

    if yes then the class contains one variable called a thats why class object has 2 bytes in your case otherwise on gcc and on visual studio it will show 4

  3. #3
    Registered User jdragyn's Avatar
    Join Date
    Sep 2009
    Posts
    92
    Because that is what you told it to output. What were you expecting?

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    Bangalore,INDIA
    Posts
    14
    Quote Originally Posted by RockyMarrone View Post
    R u working on Turbo C on Microsoft Windows ????

    if yes then the class contains one variable called a thats why class object has 2 bytes in your case otherwise on gcc and on visual studio it will show 4
    but it is privately derived..according to book is is not possible.. thats why i am confusing...

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by raj.knd View Post
    but it is privately derived..according to book is is not possible.. thats why i am confusing...

    Hey dude it doesn't matter the class variable is of type private if it will be public or protected then also it will not matter
    the only variable which dosn't include in the class objects memory will be static


  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Privately derived means the public and procted members of the base class will be treated as the private member in the child class then i think from the above post of mine u can conclude that it will not matter in any way

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    raj.knd - you reported your own post to the moderators to try and get more help. That reporting link is not there for this reason.

    Thread Closed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 02:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 03:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 04:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21