HI, Q1: Destructor of B is not called because it doesn't have Run time type information as there is no virtual function. By have a declaration like A *b= new B(); Application only know that type of object b is A so when this object get destroyed, only Class A destructor is called.
Q2: Virtual Call have minimum size of Vbptr ( virtual pointer) and size of any pointer(address) on 32 bit architecture is 4 bytes. On Sat, Jul 16, 2011 at 10:51 PM, Anika Jain <anika.jai...@gmail.com> wrote: > Q.1 what is the output of following program? > > #include <iostream> > using namespace std; > class A > { > public: > A() > { cout<<"Constructing A"<<endl; > } > > ~A() > { cout<<"Destructing A"<<endl; > } > }; > class B : public A > { > public: > B() > { > cout<<"Constructing B"<<endl; > } > ~B() > {cout<<"Destructing B"<<endl; > > } > }; > int main() > { > A *b=new B; > delete b; > } > how is its output as: > > constructing A > constructing B > destructing B > ?? > > > Q2. Determine output. > class A > { int a; > public: > > virtual void f() > { > } > }; > class B : private A > { int b; > public: > void f() > { > } > }; > int main() > { > cout<<sizeof(A)<<endl; > cout<<sizeof(B)<<endl; > > } > its output is: > 8 12 > > virtual functions do occupy 4 bytes ?? how?? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.