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

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


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


C++ programming language part- 59 Virtual Base Class


Virtual Base Class

When the same class is inherited more than once via multiple paths, multiple copies of the base class members are created in memory. By declaring the base class inheritance as virtual, only one copy of the base class is inherited.

Program 43_4
//virtual base class.demo
class A                                     // base class defined
{
  public:
  void dis()
   {
   cout<<" The verible of first base class is a \n ";
   }
};
class B:virtual public A            //virtual base class defined
{
  public:
  void dis()
{
   cout<<" The verible of virtual base class1 is b \n";
 }
};
class C:virtual public A                        //virtual base class defined
{
  public:
  void dis()
{
   cout<<" The verible of virtual base class is2 c \n";
 }
};
class D:public B,public C                    //not possible without class B/C :virtual public A
{
  public:
  void dis()
{
  cout<<" The verible of first base class is  d \n";
 }
};
void main()
{ D K;               // K is called object
   K.A::dis();     // not possible without class B/C :virtual public A
   K.B::dis();      //  these are not ambigious
   K.C::dis();
   K.D::dis(); }



Finally follow the folling program 43_5
            class A                                     //class defined
            {
              public:
              int p1;                                    // to get it from derived class
              public:
              void data_out()
{cout<<" The verible of first base class is "<
            };
              class B:virtual public A                      //class defined
            {
              public:
              int p2;                                     // to get it from derived class
              public:
              void data_out()
            {cout<<" The verible of second base class is "<
             };
               class C:virtual public A                     //class defined
{



              public:
              int p3;                                    // to get it from derived class
              public:
              void data_out()
             {cout<<" The verible of Tsecond base class is "<
            };
              class derived:public B,public C  // this is derived class named derived
            {           
              public:
               int p4;
              void data_get(int x,int y,int z)
             {   p1=x;
                  p2=y;
                  p3=z;
                  p4=x+y+z;}
             void data_out()
            {cout<<" The total are = "<
            };         
            void main()
{ derived K;                 // K is called object
               K.data_get(25,50,75);
               K.A::data_out();        //  these are not ambigious
              K.B::data_out();
               K.C::data_out();

               K.derived::data_out(); }




Part- 86 assign the content of twostring


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