开发环境:QtCreator C++
1 using namespace std;
2
3 /* 基类汽车 */
4 class Car
5 {
6 public:
7 Car() {}
8 virtual ~Car() {}
9 virtual void move(void);
10 };
11
12 /* 基本属性汽车运动 */
13 void Car::move(void)
14 {
15 cout << __PRETTY_FUNCTION__ << endl;
16 cout << typeid(*this).name() << endl;
17 }
18
19 class CarSmall : public Car
20 {
21 public:
22 CarSmall() {}
23 ~CarSmall() {}
24
25 void move(void) override ;
26
27 };
28
29 void CarSmall::move(void)
30 {
31 cout << __PRETTY_FUNCTION__ << endl;
32 cout << typeid(*this).name() << endl;
33 }
34
35 int main()
36 {
37 cout << "Hello World!" << endl;
38 cout << __PRETTY_FUNCTION__ << endl;
39
40 Car car;
41 car.move();
42
43 CarSmall carSmall;
44 carSmall.move();
45
46 return 0;
47 }
编译输出: