#include<iostream.h> class shape {public: int a; shape(int t) { a=t; } virtual void area() { cout<<"shape\n"; } }; class circle: public shape { public: void area(); circle(int x):shape(x){} }; void circle::area() { cout<<"\ncircle\n"; } void f(shape &h) {h.area(); } void main() { shape objs(1); f(objs); cout<<objs.a; circle objc(2); f(objc); cout<<objc.a<<endl; }
时间: 2024-10-07 04:19:26