know yourselves. information, computer, 7 wonders, various.

Saturday, November 11, 2017

C++ programming language part: 53 Overriding Base Class Members


Overriding Base Class Members

A base class member can be overridden by defining a derived class member with the same name. But the member of derived class have the same signature as those in base class.

Program 42_2
            class a_base                 //class defined
            { public:
               void display()
             {cout<<"This is bass class \n"; }
   int x;
             };
           
 class b_derived:public a_base
            { public:
               void display()           // the same name as base class
            { cout<<"This is derived class \n"; }
               int x;
            };
           
 void main()
{
 a_base A;
 A.display();
 A.x=20;
 cout<<"the A.x =  "<
 b_derived B;                           // B is called object
 B.display();                 //would be B->display() if pointer
 B.x=40;
 cout<<"the A.x = "<
 // A.a_base::x=60;
 // cout<<"the A.a_base::x= "<
 B.a_base::x=60;
 cout<<"the B.a_base::x= "<
 a_base c=A;
 cout<<"the c.x = "<

 }






জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯