forked from wenpinn/yzu2021pdex_b
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCAR
66 lines (64 loc) · 1.04 KB
/
CAR
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
63
64
65
66
#include <iostream>
#include <string>
using namespace std;
class CCAR {
private:
string nickname;
protected:
int light;
int wheel;
public:
CCAR() :light(2)
{
wheel = 5;
cout << "car's constructor(wheel=" << wheel << ")" << endl;
}
CCAR(string nickname) :light(2)
{
wheel = 5;
this->nickname = nickname;
cout << "car's constructor(nickname=" << nickname << ")" << endl;
}
~CCAR()
{
cout << "car's destructor" << "(" << nickname << ")" << endl;
}
void start()
{
cout << "car's start" << endl;
}
void stop()
{
cout << "car's stop" << endl;
}
void turn()
{
cout << "car's turn" << endl;
}
};
//--------------------------
class CBMW : public CCAR {
public:
CBMW() { light = 4; wheel = 4; cout << "bmw's constructor" << endl; }
~CBMW() { cout << "bmw's destructor" << endl; }
void Abs()
{
cout << "bmw's abs" << endl;
}
void start()
{
cout << "bmw's start" << endl;
CCAR::start();//scope operator
//CCAR c;
//c.start();
}
};
//--------------------------
int main(int argc, const char * argv[]) {
CBMW bmw;
// bmw.light=3;
bmw.start();
bmw.Abs();
bmw.stop();
return 0;
}