-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cc
More file actions
58 lines (46 loc) · 1.25 KB
/
Copy pathmain.cc
File metadata and controls
58 lines (46 loc) · 1.25 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
#include <cstdlib>
#include <cstdarg>
#include <iostream>
#include <string>
struct IMovable {
virtual ~IMovable() = default;
virtual void Move(int speed, ...) = 0;
};
class Car: public IMovable {
public:
Car() = default;
~Car() override = default;
void Move(int speed, ...) override {
std::cout << "Driving..." << std::endl;
std::cout << "speed = " << speed << std::endl;
va_list ap;
va_start(ap, speed);
char* const dest = va_arg(ap, char* const);
std::cout << "destination = " << dest << std::endl;
va_end(ap);
}
};
class Helicopter : public IMovable {
public:
Helicopter() = default;
~Helicopter() override = default;
void Move(int speed, ...) override {
std::cout << "Passing..." << std::endl;
std::cout << "speed = " << speed << std::endl;
va_list ap;
va_start(ap, speed);
int height = va_arg(ap, int);
std::cout << "height = " << height << std::endl;
va_end(ap);
}
};
int main() {
IMovable *car = new Car();
car->Move(82, "A");
delete car;
std::cout << std::endl;
IMovable *helicopter = new Helicopter();
helicopter->Move(300, 4500);
delete helicopter;
return EXIT_SUCCESS;
}