Commit | Line | Data |
---|---|---|
78c62cee SW |
1 | /* This test script is part of GDB, the GNU debugger. |
2 | ||
7b6bb8da | 3 | Copyright 1999, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
78c62cee SW |
4 | Free Software Foundation, Inc. |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | class Type1{ | |
21 | public: | |
22 | int foo(){ | |
23 | return 11; | |
24 | } | |
25 | }; | |
26 | ||
27 | class Type2{ | |
28 | public: | |
29 | int foo(){ | |
30 | return 22; | |
31 | } | |
32 | }; | |
33 | ||
34 | class Type3{ | |
35 | public: | |
36 | int foo(int){ | |
37 | return 33; | |
38 | } | |
39 | int foo(char){ | |
40 | return 44; | |
41 | } | |
42 | }; | |
43 | ||
44 | class Type4 { | |
45 | public: | |
46 | int a; | |
47 | int b; | |
48 | }; | |
49 | ||
50 | int foo (Type3, float) | |
51 | { | |
52 | return 55; | |
53 | } | |
54 | ||
55 | class MyPointer{ | |
56 | Type1 *p; | |
57 | public: | |
58 | MyPointer(Type1 *pointer){ | |
59 | p = pointer; | |
60 | } | |
61 | ||
62 | Type1 *operator->(){ | |
63 | return p; | |
64 | } | |
65 | }; | |
66 | ||
67 | template <typename T> class SmartPointer{ | |
68 | T *p; | |
69 | public: | |
70 | SmartPointer(T *pointer){ | |
71 | p = pointer; | |
72 | } | |
73 | ||
74 | T *operator->(){ | |
75 | return p; | |
76 | } | |
77 | }; | |
78 | ||
79 | ||
80 | class A { | |
81 | public: | |
82 | int inta; | |
83 | int foo() { return 66; } | |
84 | }; | |
85 | ||
86 | class B { | |
87 | public: | |
88 | A a; | |
89 | A* operator->(){ | |
90 | return &a; | |
91 | } | |
92 | }; | |
93 | ||
94 | class C { | |
95 | public: | |
96 | B b; | |
97 | B& operator->(){ | |
98 | return b; | |
99 | } | |
100 | }; | |
101 | ||
102 | class C2 { | |
103 | public: | |
104 | B b; | |
105 | B operator->(){ | |
106 | return b; | |
107 | } | |
108 | }; | |
109 | ||
110 | int main(){ | |
111 | Type1 mt1; | |
112 | Type2 mt2; | |
113 | Type3 mt3; | |
114 | ||
115 | Type4 mt4; | |
116 | mt4.a = 11; | |
117 | mt4.b = 12; | |
118 | ||
119 | MyPointer mp(&mt1); | |
120 | Type1 *mtp = &mt1; | |
121 | ||
122 | SmartPointer<Type1> sp1(&mt1); | |
123 | SmartPointer<Type2> sp2(&mt2); | |
124 | SmartPointer<Type3> sp3(&mt3); | |
125 | SmartPointer<Type4> sp4(&mt4); | |
126 | ||
127 | mp->foo(); | |
128 | mtp->foo(); | |
129 | ||
130 | sp1->foo(); | |
131 | sp2->foo(); | |
132 | ||
133 | sp3->foo(1); | |
134 | sp3->foo('a'); | |
135 | ||
136 | sp4->a; | |
137 | sp4->b; | |
138 | ||
139 | Type4 *mt4p = &mt4; | |
140 | mt4p->a; | |
141 | mt4p->b; | |
142 | ||
143 | A a; | |
144 | B b; | |
145 | C c; | |
146 | C2 c2; | |
147 | ||
148 | a.inta = 77; | |
149 | b.a = a; | |
150 | c.b = b; | |
151 | c2.b = b; | |
152 | ||
153 | a.foo(); | |
154 | b->foo(); | |
155 | c->foo(); | |
156 | ||
157 | b->inta = 77; | |
158 | c->inta = 77; | |
159 | c2->inta = 77; | |
160 | ||
161 | return 0; // end of main | |
162 | } | |
163 |