Home > Back-end >  C consult!!!!! About the virtual function
C consult!!!!! About the virtual function

Time:10-19

 # include 
using namespace std;

Class A
{
Public:
Void virtual show () {cout<" Class A "& lt; Void the view () {cout<" Class A view "& lt; };

Class B: public A
{
Public:
Void the show () {cout<" Class B "& lt; Void sh () {cout<" Class B sh & lt;" };

Class C: public B
{
Public:
Void the show () {cout<" Class C "& lt; Void sh () {cout<" Class C sh & lt;" };

Void main ()
{
A, A, * pa=& amp; a;
B, B * pb=& amp; b;
C C;
Pa - & gt; Show ();
Pa=& amp; b;
Pa - & gt; Show ();
Pa=& amp; c;
Pa - & gt; Show ();
(B *) (pa) - & gt; Show ();
(B *) (pa) - & gt; Sh ();
(pa) (C *) - & gt; Show ();
(pa) (C *) - & gt; Sh ();
(pa) (C *) - & gt; The view ();
getchar();
}


To solve, don't understand why the four last sentence is that
 (pa) (B *) - & gt; Show (); 
(B *) (pa) - & gt; Sh ();
(pa) (C *) - & gt; Show ();
(pa) (C *) - & gt; Sh ();

CodePudding user response:

Casts a pointer type
  • Related