Simple example of a virtual function

xiaoxiao2021-03-13  202

#include

Using namespace std;

Class A

{

Void fun1 ()

{

FUN2 ();

}

Virtual void fun2 ()

{

COUT << "FUN2 in Class A";

}

}

Class B: Public Class A

{

Virtual void fun2 ()

{

COUT << "Fun2 in classb";

}

}

void main ()

{

B m_example;

m_example.fun1 ();

}

Screen output: fun2 in classb

转载请注明原文地址:https://www.9cbs.com/read-129186.html

New Post(0)