File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 200
200
\end {block }
201
201
\end {frame }
202
202
203
+ \begin {frame }[fragile]
204
+ \frametitlecpp [98]{Overloading}
205
+ \begin {block }{Overloading}
206
+ \begin {itemize }
207
+ \item We can have multiple functions with the same name
208
+ \item They must have different parameter lists
209
+ \item A different return type alone is not allowed
210
+ \item Default arguments can cause ambiguities
211
+ \item All functions with the same name form an `` overload set''
212
+ \end {itemize }
213
+ \end {block }
214
+ \begin {exampleblock }{}
215
+ \begin {cppcode* }{gobble=6}
216
+ int sum(int b); // 1
217
+ int sum(int b, int c); // 2, ok, overload
218
+ // float sum(int b, int c); // disallowed
219
+ sum(42); // calls 1
220
+ sum(42, 43); // calls 2
221
+ int sum(int b, int c, int d = 4); // 3, overload
222
+ sum(42, 43, 44); // calls 3
223
+ sum(42, 43); // error: ambiguous, 2 or 3
224
+ \end {cppcode* }
225
+ \end {exampleblock }
226
+ \end {frame }
227
+
203
228
\begin {frame }[fragile]
204
229
\frametitlecpp [98]{Functions}
205
230
\begin {exercise }{Functions}
You can’t perform that action at this time.
0 commit comments