|
Function is a named part of a program that can be called from other parts
of the program so many times as it is necessary. It consists of type definition
for the value to be returned, name, formal parameters, and a composite
operator (block) of actions to be performed. Amount of passed parameters
is limited and cannot exceed 64.
関数は、それが必要なときに他のプログラムの部分から、何度も呼び出すことが出来るプログラムの名前を付けられた部分です。それは、型の定義で構成されます。返される値、名前、仮引数、そして実行されるべき動作の重文処理(ブロック)です。渡すパラメータの量は限られており、64個を超えることはできません。
Examples:
例:
double // type of value to be returned
返される値の型
linfunc (double x, double a, double b) // function name and parameters list
関数名とパラメーターリスト
{
// composite operator
重文処理
return (a + b); // returned value
戻り値
}
The "return" operator can return the value of the expression
included into this operator. If necessary, the expression value can be
transformed into the type of function result. A function that does not
return values must be of "void" type.
"retrun" 処理は、この演算子に含まれる式の値を返すことができます。もし、必要であるなら、式の値は、関数の結果の型に変換できます。値を返さない関数は
"void" 型とする必要があります。
Examples:
例:
void errmesg(string s)
{
Print("error: "+s);
}
Parameters to be passed to the function can have default values that are defined by constants of the appropriate type.
関数に渡されるパラメーターは、適切な型の定数で定義されている規定値を持つことができます。
Examples:
例:
int somefunc(double a, double d=0.0001, int n=5, bool b=true, string s="passed string")
{
Print("Required parameter a=",a);
Print("The following parameters are transmitted: d=",d," n=",n," b=",b," s=",s);
return (0);
}
If the default value was assigned to a parameter, all follow-up parameters must have the default value, too.
もし、規定値がパラメータに割り当てられたなら、後に続くすべてのパラメータも規定値を持っている必要があります。
Example of a wrong declaration:
間違った宣言の例:
int somefunc(double a, double d=0.0001, int n, bool b, string s="passed string")
{
}
|