Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using std::cout;
- using std::endl;
- //抽象クラスvehicleの定義
- class vehicle{
- public:
- virtual void start(void)=0;
- virtual void stop(void)=0;
- };
- //vehicleを継承したクラスcarの定義
- class car: public vehicle{
- public:
- void start(void){
- cout << "car start" << endl;
- }
- void stop(void){
- cout << "car stop." << endl;
- }
- };
- //vehicleを継承したクラスmotorcycleの定義
- class motorcycle: public vehicle{
- public:
- void start(void){
- cout << "motorcycle start" << endl;
- }
- void stop(void){
- cout << "motorcycle stop." << endl;
- }
- };
- //テスト部
- int main(void){
- vehicle* mycar;
- mycar = new car();
- (*mycar).start();
- (*mycar).stop();
- return 0;
- }
Add Comment
Please, Sign In to add comment