Arguments and Argument List - Practical Electron Microscopy and Database - - An Online Book - |
||||||||
Microanalysis | EM Book http://www.globalsino.com/EM/ | ||||||||
================================================================================= | ||||||||
A function in DM has a name, an argument list, a return type, and a body. In C++ and thus in DM, all functions must be declared before they are used. For instance, "result (EMadd (1,2) + "\n")" in Figure 1121 cannot be the first line in the script because this use has to locate after the function EMadd is declared, namely the block for "number EMadd( number EMa, number EMb ) ...". Figure 1121. Function and argument list. (Script) In C++ and DM, you can give a parameter a default value that is automatically used when no argument corresponding to that parameter is specified in a call to a function. Default arguments can be used to simplify calls to complex functions. On the other hand, such arguments can sometimes be used as a "shortcut" form of function overloading. A default argument is specified in a manner, syntactically, similar to a variable initialization. One reason that default arguments are used is that they enable the
programmer to manage greater complexity. In such situations, quite frequently a function will contain more parameters than are
required for its most common usage. Therefore, when the default arguments apply, you
only need remember and specify the arguments that are meaningful to the exact
situation, not all those needed for the most general cases. Some important points to remember, when you create a function that has
default argument values, are:
|
||||||||
================================================================================= | ||||||||
|
||||||||