/*多态的实现。*/#include <iostream>#include <string>
using namespace std;
class cbuilding{
string name; //char * name;public: void set(string strName); void display() { cout<<"建筑是"<< name<<endl; }};
void cbuilding::set(string str){ name = str;}
class bridge:public cbuilding{
float bridgeLength;public: void setlength(float length) { bridgeLength = length; } void display() { cbuilding::display(); cout<<"桥的长度是"<<bridgeLength<<endl; }};void main(){ bridge b; //string s1="zhongguo"; b.set("杭州钱塘江三桥"); b.setlength(200.003); b.display(); return;}
posted @ 2011-07-16 16:11 susu 阅读(100) | 评论 (0) | 编辑 收藏
Powered by: C++博客 Copyright © susu