#include<iostream.h> class shape {public: int a; shape(int t) { a=t; } virtual void area()=0; }; class circle: public shape { public: void area(); circle(int x):shape(x){} }; class square :public shape { public: void area(); square(int x):shape(x){} }; void circle::area() { cout<<"circle\n"; } void square::area() { cout<<"\nsquare\n"; } void f(shape &h) {h.area(); } void main() { circle objc(2); f(objc); cout<<objc.a; square objs(3); f(objs); cout<<objs.a<<endl; }
时间: 2024-10-19 22:30:19