1 00:00:00,950 --> 00:00:08,060 In general, function names have the same rules for variables, so they must begin with a letter or 2 00:00:08,060 --> 00:00:13,850 an underscore and cannot contain spaces or other presentation characters yet. 3 00:00:13,880 --> 00:00:27,590 So now I'm going to write some functions integer my function here an integer like my function. 4 00:00:29,370 --> 00:00:33,180 And when we do the integer it is. 5 00:00:34,440 --> 00:00:45,240 This is the illegal and the compiler compiler will or will not compile here will not compile. 6 00:00:46,510 --> 00:00:47,030 Here. 7 00:00:48,520 --> 00:00:49,240 And. 8 00:00:50,870 --> 00:00:58,640 Uh, as I said earlier, they must begin with a letter or an underscore character and cannot contain 9 00:00:58,640 --> 00:01:05,270 spaces, as you can see here, or other plantation characters, for example, like Toad comma here, 10 00:01:05,300 --> 00:01:09,440 they cannot contain any punctuation characters for. 11 00:01:09,440 --> 00:01:16,460 So following the general principle of self documenting code, you shall name the function according 12 00:01:16,460 --> 00:01:18,560 to what it does. 13 00:01:18,800 --> 00:01:25,490 So there is one exception, and these are the special functions used to provide overloads for operators, 14 00:01:25,850 --> 00:01:27,950 which is mostly punctuation symbols. 15 00:01:27,950 --> 00:01:32,420 So these functions have a name in the form here. 16 00:01:32,420 --> 00:01:36,350 For example the multi here where the. 17 00:01:37,610 --> 00:01:43,360 Mold is like describing the function which will will multiply the two values one by one. 18 00:01:43,370 --> 00:01:50,540 So operators are one example of overloading here so you can overload any function that is used the same 19 00:01:50,540 --> 00:01:57,230 name, but provide implementations with different parameter types or different parameter numbers. 20 00:01:57,230 --> 00:01:58,730 We can make it like that. 21 00:01:58,730 --> 00:02:01,290 For example, integer multiple. 22 00:02:01,340 --> 00:02:03,110 We can make multiply. 23 00:02:03,530 --> 00:02:05,630 We can multiply three numbers one by one. 24 00:02:05,630 --> 00:02:15,140 Here, for example l h as integer or h as if you make it like that or just make it integer, for example. 25 00:02:16,960 --> 00:02:19,170 Actually they will return the same value. 26 00:02:19,180 --> 00:02:22,550 This is just a different writing in C++ here. 27 00:02:22,570 --> 00:02:26,280 As you can see, we're going to get error because they are the two same function. 28 00:02:26,290 --> 00:02:30,660 As you can see, the redefinition of multi, multi, multi are. 29 00:02:30,670 --> 00:02:38,830 So if we make add another parameter integer x l x, we're going to make the overloading function here 30 00:02:38,830 --> 00:02:46,240 and we're going to return the return the LCS multiplied by an error and multiply and multiply it by 31 00:02:46,300 --> 00:02:49,450 the x h as here. 32 00:02:49,480 --> 00:02:55,630 And if you make it like that, a standard c out. 33 00:02:57,140 --> 00:03:01,520 See here and here, the mold, we're going to multiply. 34 00:03:01,580 --> 00:03:08,510 We're going to call this here eight or 910. 35 00:03:08,510 --> 00:03:15,950 So in this case, the multiply function will fill this court here. 36 00:03:16,070 --> 00:03:22,250 This court will call this function because this takes parameters and where we gave this function to 37 00:03:22,250 --> 00:03:22,980 parameters. 38 00:03:23,000 --> 00:03:32,120 If you make it like that, this is going to call the the third function, the second function here that 39 00:03:32,120 --> 00:03:35,420 we have three parameters and we are calling this function. 40 00:03:35,420 --> 00:03:39,320 So and this named the function overloading here. 41 00:03:40,140 --> 00:03:45,120 As we can see here, we multiplied the tree numbers one by one here. 42 00:03:45,120 --> 00:03:45,780 So. 43 00:03:47,450 --> 00:03:50,510 We have function parameters, the function here. 44 00:03:50,720 --> 00:03:53,390 They may not have any parameters like this. 45 00:03:53,390 --> 00:03:58,820 Here, for example, we can create a mute function, but with that parameters like this. 46 00:03:58,820 --> 00:04:03,170 But they let us just create without parameters. 47 00:04:03,170 --> 00:04:05,220 But we'll have the return value. 48 00:04:05,240 --> 00:04:15,920 So in which case the case is the function is the fate defined with a pair of empty parenthesis like 49 00:04:15,920 --> 00:04:17,210 this here, for example. 50 00:04:17,210 --> 00:04:25,400 So a function, the function definition must give the type and name of the parenthesis parameters between 51 00:04:25,400 --> 00:04:27,140 parenthesis like this here. 52 00:04:27,140 --> 00:04:28,250 So. 53 00:04:29,680 --> 00:04:36,100 In many cases, the functions will have a fixed number of parameters, but you can write functions with 54 00:04:36,100 --> 00:04:37,870 a variable number of parameters. 55 00:04:37,870 --> 00:04:42,640 So you can also define functions with the default values or some of the parenthesis. 56 00:04:42,760 --> 00:04:45,220 So sum of parameters. 57 00:04:45,220 --> 00:04:52,210 So in effect a providing a function that overloads itself on the number of parameter parameters passed 58 00:04:52,210 --> 00:04:53,620 to the function. 59 00:04:53,620 --> 00:05:00,580 So variable argument list and default arguments will be covered later in this course here. 60 00:05:00,820 --> 00:05:07,990 We can also make the this specify the exceptions in C++ function here. 61 00:05:08,020 --> 00:05:14,080 The functions also can be marked to indicate whether they will throw an exception. 62 00:05:14,080 --> 00:05:18,670 So more details about exceptions will be given in next lecture. 63 00:05:18,670 --> 00:05:22,510 But there are two syntax you need to be aware of. 64 00:05:22,510 --> 00:05:29,320 So earlier versions of C++ allowed you to use the trough specified for. 65 00:05:30,910 --> 00:05:34,330 Specified on the function three ways. 66 00:05:35,280 --> 00:05:43,350 Firstly you provide a comma separated list of types of the exceptions that may be shown by code in the 67 00:05:43,350 --> 00:05:44,190 function here. 68 00:05:44,760 --> 00:05:50,250 And the second, you can provide an ellipsis like this here. 69 00:05:53,100 --> 00:05:58,680 Ellipses or, uh, which means that the function may prove an exception. 70 00:05:58,680 --> 00:06:06,100 And thirdly, you can provide an empty pair of parenthesis, which means that the function will not 71 00:06:06,120 --> 00:06:07,320 prove an exception. 72 00:06:07,320 --> 00:06:12,570 So the syntax here throw in exceptions to exceptions. 73 00:06:12,570 --> 00:06:14,610 Rule looks like this, for example. 74 00:06:16,110 --> 00:06:19,290 We're going to specify the exceptions. 75 00:06:19,290 --> 00:06:23,880 For example, overflow of overflow error and. 76 00:06:25,420 --> 00:06:30,970 Do we going to make, for example, do something which potentially. 77 00:06:32,590 --> 00:06:35,070 May overflow flow. 78 00:06:35,380 --> 00:06:40,360 So the trough specified has been deprecated in C++ 11. 79 00:06:40,360 --> 00:06:47,470 As you can see, the compiler will say the dynamic exception specified for overflow of error is deprecated. 80 00:06:47,470 --> 00:06:50,320 Consider using no accept false. 81 00:06:50,320 --> 00:06:59,230 Instead here we can change ignore accept files so it froze specified has been deprecated in C++ is largely 82 00:06:59,230 --> 00:07:03,730 because the ability to indicate that the type of function was not useful. 83 00:07:03,730 --> 00:07:10,360 So however, the version of Shrove that indicates that no exception will be thrown was found to be useful 84 00:07:10,360 --> 00:07:18,760 because it enables the compiler to optimize code by providing no code infrastructure to handle expectations. 85 00:07:18,760 --> 00:07:28,510 Here are exceptions here, so the C++ 11 retains this behavior with no except specified and the Knox 86 00:07:28,510 --> 00:07:29,200 except specified. 87 00:07:29,230 --> 00:07:36,160 Here, we can delete it this false here and with no access specified, we're going to check. 88 00:07:37,410 --> 00:07:44,760 Check the parameter and handle overflow appropriately. 89 00:07:47,540 --> 00:07:48,050 Here.