Что будет напечатано в результате работы следующей программы на
Си++?
#include <iostream.h>
class X
{
public:
virtual void f () { cout << "X::f" << endl; g (); }
void g () { cout << "X::g" << endl;}
};
class Y : public X
{
public:
void f () { cout << "Y::f" << endl; }
void g () { cout << "Y::g" << endl; f (); }
};
class Z : public Y
{
public:
void f () { cout << "Z::f" << endl; }
void g () { cout << "Z::g" << endl; f (); }
};
void P ( X * px, Y * py )
{
px->f ();
px->g ();
py->f ();
py->g ();
delete px;
delete py;
}
int main ()
{
P ( new X, new Y );
cout << "------------------------------" << endl;
P ( new Y, new Z );
return 0;
}