Home > Back-end >  C succession
C succession

Time:10-01

# include & lt; Iostream>
using namespace std;

Class A
{
Private:
Int a;
Public:
A (int I) : A (I) {}
Virtual void print ()
{
Cout<& lt;" AAAA \ n ";
Cout & lt; }
Int get_a ()
{
return a;
}
};
Class B
{
Private:
Int b;
Public:
B (int j) : B (j) {}
Void the print ()
{
Cout<& lt;" BBBB \ n ";
Cout & lt; }
Int get_b ()
{
return b;
}
};
Class C: public A, public B
{
Int c;
Public:
C (int, int j, int k) : A (I), B (j), C (k) {}
Void the print ()
{
Cout<& lt;" CCC \ n ";
A: : print ();
B: : print ();
}
//use the print () with the scope resolution
Void get_ab ()
{
Cout & lt; }
//use get_a () and get_b () without the scope resolution
};
Int main ()
{
C (5, 8, 10 x);
A * ap=& amp; X;
B * bp=& amp; X;
C * cp=& amp; X;
Ap - & gt; Print ();//use C: : print ();//?????????????????????????????????
Cout<& lt;" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n";
Bp - & gt; Print ();//use B: : print ();
Cp - & gt; print();
Cout<& lt;" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ";
//bp - & gt; A: : print ();//as if x is inherited from B only,
//always access A: A: print ();
X.A: : print ();//use A: : print ();
Cout<& lt;" ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ n ";
X.g et_ab ();
return 0;
}

Don't understand why on//?????? Where is called C: : print (); And next does B: : print.
Seek expert advice,

CodePudding user response:

This is a polymorphic.