???C++??Щ?????NO
???????????? ???????[ 2013/1/4 10:27:35 ] ????????
????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
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11