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

Saturday, November 11, 2017

C++ programming language part: 57 Protected base Class Inheritance


Protected base Class Inheritance


It is possible to inherit a base class as protected. All public and protected members of the base class become protected members of the derived class. In the following program data_inP() and data_outP() are public members of base, they become protected members of derived when it is inherit using the protected access specifier. This means that they will not be accessible inside main().

Program 43_11
            //protected base class inherit.demo
            class base                     // base class defined
            {
              protected:
              int p1,p2;       // to get it from derived class
           
              public:
              void data_inP(int a,int b)
               {
               p1=a;
              p2=b;
               }
              void data_outP()
              {
              cout<
              }    
            };
            class derived:protected base    // inherit base as protected.
            {
              int q;
              public:
              void data_inQ()
              {
              data_inP(10,20);
              q=p1*p2;
              }
              void data_outAll()
              { cout<<"the result="<
                  void data_outP();  }
            };
            void main()
             { derived K;                           // K is called object
               // K.data_inP(25,50);                        // not possible, protected of derived
               K.data_inQ();
               K.data_outAll();

               //K.data_outP     }                 // not possible, protected of derived


Part- 86 assign the content of twostring


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


Wednesday, November 8, 2017

C++ programming language part- 58 Ambiguity of Multiple Classes


Ambiguity of Multiple Classes


When a class inherits from multiple base classes, the compiler become ambiguous. The ambiguity can be resolve using the scope resolution operator or it can also be resolved by redefined in the derived class.   

Program 43_2
           
              // Ambigious multiple inherit
            class A                         //base class defined
            {
              protected:
              int p1;                        // to get it from derived class
             
              public:
              void data_out()
               {
               cout<<" The verible of first base class is "<
               }
            };
              class B                                   //base class defined
              {
              protected:
              int p2;                        // to get it from derived class
           
 
              public:
              void data_out()
               {
               cout<<" The verible of second base class is "<
               }
            };                                  // here are two base class named A & B

              class derived:public A,public B                     //multiple inheritance of class
              {         
              public:
              void data_get(int x,int y)
                {
                  p1=x;
                  p2=y;
                }
            };          // this is derived class named derived
           
            void main()
              {
               derived K;                  // K is called object
               K.data_get(25,50);
               //K.data_out();          // would flag an error, cause these are ambigious
               //K.data_out();
               K.A::data_out();      // Data will get from class A
               K.B::data_out();      // Data will get from class B
}
Program 43_3
              // Ambigious multiple inherit
            class A             //class defined
            {
              protected:
              int p1;       // to get it from derived class

              public:
              void data_out()
               {
               cout<<" The verible of first base class is "<
               }
            };
              class B                       //class defined
              {
              protected:
              int p2;       // to get it from derived class
             
           



  public:
              void data_out()
               {
               cout<<" The verible of second base class is "<
               }
            };          // here are two base class named A & B

              class derived:public A,public B  // multiple inheritance of base class
              {         
              public:
              void data_get(int x,int y)
                {
                  p1=x;
                  p2=y;              
                }

              void data_out()
              {A::data_out();                        // Data will get from class A, called redifined
                B::data_out();}                      // Data will get from class B, called redefined
            };         
            void main()
              { derived K;                // K is called object
               K.data_get(25,50);
               K.data_out();}           //  these are not ambigious




Part- 86 assign the content of twostring


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