Advertisement

C++多态:涉及虚函数、重载和抽象类

阅读量:

**【c++

复制代码
 //多态性.cpp

    
  
    
 #include<iostream>
    
 #include<string.h>
    
 using namespace std;
    
  
    
 class CBuilding  //建筑类 
    
 {
    
 	private:
    
 		string name;
    
 	public:
    
 		void set(string str)
    
 		{
    
 			name=str;
    
 		}
    
 		void display()
    
 		{
    
 			cout<<"建筑是:"<<name<<endl;
    
 		}
    
 } ; 
    
  
    
 class CBridge:public CBuilding  //桥类 
    
 {
    
 	private:
    
 		double length;
    
 	public:
    
 		void setLength(double i)
    
 		{
    
 			length=i;
    
 		}
    
 		void display()
    
 		{
    
 			CBuildin

全部评论 (0)

还没有任何评论哟~