c++

Program using virtual function causing defined behaviour.

#include #include class base { public: base() { cout<<"Constructing base n"; } virtual ~base() { cout<<"Destructing base n"; } }; class derived: public base { public: derived() { cout<<"Constructing derived n"; } ~derived() { cout<<"Destructing derived n"; } }; void main() { clrscr(); derived *d = new derived(); base *b = d; delete b; getch(); […]

Program without virtual function causing undefined behaviour.

#include #include class base { public: base( ) { cout<<"Constructing base n"; } ~base( ) { cout<<"Destructing base n"; } }; class derived: public base { public: derived() { cout<<"Constructing derived n"; } ~derived( ) { cout<<"Destructing derived n"; } }; main( ) { clrscr(); derived *d = new derived(); base *b = d; delete […]

Program for the implementation of hybrid inheritance.

#include #include class student { protected: int roll_number; public: void get_number(int a) { roll_number=0; } void put_number() { cout<<roll_number<<endl; } }; class test:public student { protected: float sub1,sub2; public: void get_marks(float x,float y) { sub1=x; sub2=y; } void put_marks() { cout<<sub1<<endl<<sub2<<endl; } }; class score { protected: float score; public: void get_score(float s) { score=s; […]