C ++ level small test

xiaoxiao2021-03-05  51

#include "stdafx.h" #include using namespace std;

Class base {public: Virtual void f (int); Virtual Void F (Double); Virtual Void G (INT i = 10);

Void Base :: f (int) {cout << "Base :: f (int) << endl;}

Void Base :: F (Double) {cout << "Base :: f (double) << endl;}

Void Base :: G (INT I) {cout << I << endl;

Class Derived: Public Base {public: Void F (Complex ); Void G (int i = 20); // using base :: f;

Void Derived :: F (Complex ) {cout << "Derived :: F (complex ) << Endl;}

Void derived :: g (int i) {cout << "Derived :: g (int i)" << i << endl;}

INT _TMAIN (int Argc, _tchar * argv []) {base * pb = new derived; pb-> g (); delete pb; return 0;}

What will it be output?

-----------------------------------------------

Haha - | Derived :: G (INT I) 10 (Not 20 !!)

Because the preset parameters are static types to be set, the modified function type is dynamic.

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

New Post(0)