????2???ò???????б????????????儷???

???????????????C????γ???????C???????????е?????????????????????C++?У??????ò????????????????????????????????????????????ι??????????????????????????????????????1??8???2?????????60?????μ??????????


1 class People{...};
2 class Ticket{...};
3 bool Isvalid(const People&p){...}
4 void Banding(const People& p??Ticket& t);
5 Ticket buyTicket(const People& p)
6 {
7     Ticket t;
8     if(Isvalid(p)){ return NULL };
9     //????????
10     Banding(p??&t);
11     return t;
12 }


?????????????????????????????????????????????????????????????????????Ticket t?????ú??????????????Ticket??????????????????

????????ò??????????????壬??????????????壬?????????????????????????????????????????


1 class People{...};
2 class Ticket{...};
3 bool Isvalid(const People&p){...}
4 void Banding(const People& p??Ticket& t);
5 Ticket buyTicket(const People& p)
6 {
7     if(Isvalid(p)){ return NULL };
8     Ticket t;
9     //????????
10     Banding(p??&t);
11     return t;
12 }


????3???ò????????????????

????C++???????????????????“???????”????????????????????????????????????????????κ?????????κβ??????????????????????????????????????????????????κ??????鷳????Щ????鷳?????籾???????????????C??C++????????????????????C++????????????????????????????????????????????н???????????ò??????????????????????????????????????????????????????????????????


1 #include <iostream>
2
3 class base
4 {
5     public:
6         base():a(0)??b(0){}
7         base(const int& x??const int& y)
8         :a(x)??b(y){}
9         virtual void init()
10         {
11             a=5;
12             b=5;
13             std::cout<<"in base a value is "<<a<<std::endl;
14             std::cout<<"in base b value is "<<b<<std::endl;
15         }
16
17         int get_a() const
18         {
19             return a;
20         }
21
22         int get_b() const
23         {
24             return b;
25         }
26     private:
27         int a;
28         int b;
29 };
30
31 class derived:public base
32 {
33     public:
34         derived(int x??int y):base(x??y){}
35         void init()
36         {
37             static_cast<base>(*this).init();
38         }
39 };


???????н???


in base a value is 5
in base b value is 5
a value is 2
b value is 2