-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path166.cpp
More file actions
62 lines (62 loc) · 1.3 KB
/
166.cpp
File metadata and controls
62 lines (62 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
using namespace std;
class Vehicle{
public:
Vehicle(){
cout<<"Vehicle constructor..."<<endl;
}
~Vehicle(){
cout<<"Vehicle destructor..."<<endl;
}
virtual void display()const =0;
static Vehicle * createCar();
static Vehicle * createTruck();
static Vehicle * createBoat();
};
class Car:public Vehicle{
public:
Car(){
cout<<"Car constructor..."<<endl;
}
~Car(){
cout<<"Car destructor..."<<endl;
}
void display() const{
cout<<"This is a car!"<<endl;
// puts("This is a car!");
}
};
class Truck:public Vehicle{
public:
Truck(){
cout<<"Truck constructor..."<<endl;
}
~Truck(){
cout<<"Truck destructor..."<<endl;
}
void display() const{
cout<<"This is a Truck!"<<endl;
// puts("This is a !");
}
};
class Boat:public Vehicle{
public:
Boat(){
cout<<"Boat constructor..."<<endl;
}
~Boat(){
cout<<"Boat destructor..."<<endl;
}
void display() const{
cout<<"This is a Boat!"<<endl;
// puts("This is a!");
}
};
Vehicle * Vehicle::createCar(){return new Car();}
Vehicle * Vehicle::createTruck(){return new Truck();}
Vehicle * Vehicle::createBoat(){return new Boat();}
int main(){
for(int i=0;i<1;i++)
Vehicle::createTruck()->display();
// delete Vehicle::createBoat();
}