标签:
#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; }
标签:
原文地址:http://www.cnblogs.com/leijiangtao/p/4491333.html