In general function names have the same rules for variables, so they must begin with a letter or an
underscore and cannot contain spaces or other punctuation characters here.
So now I'm going to write some functions.
Integer My function here, an integer like my function.
And when we do the integer it here.
This is the illegal and the compiler compiler will or will not compile here will not compile.
Here.
And.
Uh, as I said earlier, they must begin with a letter or an underscore character and cannot contain
spaces, as you can see here or other punctuation characters, for example, like dot comma here, they
cannot contain any punctuation characters for.
So following the general principle of Self-documenting code, you should name the function according
to what it does.
So there is one exception, and these are the special functions used to provide overloads for operators,
which is mostly punctuation symbols.
So these functions have a name in the form here, for example, the multi-year where the.
Mold is like describing the function which will will multiply the two values one by one.
So operators are one example of overloading here.
So you can overload any function that is use the same name, but provide implementations with different
parameter types or different parameter numbers.
We can make it like that, for example, integer multi-year.
We can make multiply.
We we can multiply three numbers one by one here, for example, l h s integer r h s.
If you make it like that or just make it integer, for example.
Actually they will return the same value.
This is just a different writing in C plus plus here.
As you can see, we're going to get error because they are the two same function.
As you can see the redefinition of multi year, multi, multi year.
So if we make add another parameter integer x x, we're going to make the overloading function here
and we're going to return the return, the multiply by an error and multiply in multiply it by the X
age s here.
And if you make it like that as standard C out.
See out here and here.
The most we're going to multiply.
We're going to call this here 8 or 910.
So in this case, uh, the multiply function will, uh, this code here, this code will call this function
because this takes parameters and we gave this function two parameters.
If we make it like that, uh, this is going to call the, uh, the third function.
The second function here that we have three parameters and we are calling this function.
So, and this named the function overloading here.
As you can see here, we multiplied the three numbers one by one here.
So.
Uh, we have function parameters.
The function here, they may not have any parameters like this here.
For example, we can create a function with that parameters like this.
But they let's return create without parameters, but we'll have the return value.
So in which case the case is the function is the fate defined with a pair of empty parentheses.
Uh, like this here, for example.
So a function.
The function definition must give the type and name of the parentheses parameters between parentheses
like this here.
So.
And, uh, in many cases the functions will have a fixed number of parameters.
But you can write functions with a variable number of parameters.
So you can also define functions with the default values or some of the parentheses.
So some of the parameters.
So in effect a providing a function that overloads itself on the number of parameters parameters passed
to the function.
So variable argument list and default arguments will be covered later in this course.
Here we can also make the make the specify the exceptions in C plus plus function here.
The functions also can be marked to indicate whether they will throw an exception.
So more details about exceptions will be given in next lecture.
But there are two syntaxes you need to be aware of.
So earlier versions of C plus plus allowed you to use the trough specifier.
Uh, specified on the function in three ways.
Firstly, you provide a comma separated list of types of the exceptions that may be thrown by code in
the function here.
The second you can provide an ellipsis like this.
Here.
Lapses or which means that the function may throw an exception.
And thirdly, you can provide an empty pair of parentheses, which means that the function will not
throw an exception.
So the syntax here.
Throwing exceptions to exceptions looks like this.
For example, throw we're going to specify the exceptions.
For example overflow overflow error and.
Do.
We're going to make, for example, do something which potentially.
May overflow flow.
So the trough specifier has been deprecated in C plus plus 11.
As you can see, the compiler will say the dynamic exception specifier, uh, overflow error is deprecated.
Consider using noexcept files instead.
Here we can change ignore accept files so it throws specifier has been deprecated in C plus.
Plus is largely because the ability to indicate that the type of function was not useful.
So however, the version of throw that indicates that no exception will be thrown was found to be useful
because it enables the compiler to optimize code by providing no code infrastructure to handle exceptions
here, exceptions here.
So the C plus plus 11 retains this behavior with no accept specifier and the no accept specifier.
Here we can delete this false here and add with no accept specifier.
We're going to check.
Check the parameter and handle overflow appropriately.
Here.