//程序作者:管寧
//站點:www.cndev-lab.com
//所有稿件均有版權,如要轉載,請務必聞名出處和作者
#include <iostream>
using namespace std;
class Vehicle
{
public:
Vehicle(float speed,int total)
{
Vehicle::speed = speed;
Vehicle::total = total;
}
virtual void ShowMember()=0;//純虛函數的定義
PRotected:
float speed;
int total;
};
class Car:public Vehicle
{
public:
Car(int aird,float speed,int total):Vehicle(speed,total)
{
Car::aird = aird;
}
virtual void ShowMember()//派生類成員函數重載
{
cout<<speed<<""<<total<<""<<aird<<endl;
}
protected:
int aird;
};
int main()
{
//Vehicle a(100,4);//錯誤,抽象類不能創建對象
Car b(250,150,4);
b.ShowMember();
system("pause");
}
新聞熱點
疑難解答