Guest User

Untitled

a guest
Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include<iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. //抽象クラスvehicleの定義
  6. class vehicle{
  7. public:
  8. virtual void start(void)=0;
  9. virtual void stop(void)=0;
  10. };
  11.  
  12. //vehicleを継承したクラスcarの定義
  13. class car: public vehicle{
  14. public:
  15. void start(void){
  16. cout << "car start" << endl;
  17. }
  18. void stop(void){
  19. cout << "car stop." << endl;
  20. }
  21. };
  22.  
  23. //vehicleを継承したクラスmotorcycleの定義
  24. class motorcycle: public vehicle{
  25. public:
  26. void start(void){
  27. cout << "motorcycle start" << endl;
  28. }
  29. void stop(void){
  30. cout << "motorcycle stop." << endl;
  31. }
  32. };
  33.  
  34. //テスト部
  35. int main(void){
  36. vehicle* mycar;
  37. mycar = new car();
  38. (*mycar).start();
  39. (*mycar).stop();
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment