functions
writingcallingoverloadingkeyWord fun
(or function
) followed by the return type and then the name of the function. After the name of the function parentheses(括号) must be opened to declare the types of the input arguments.
You can also use the ChucK Operator to call functions!
// call hey ( 1, 2 ) => hey => int result; // same hey( 1, 2 ) => int result; // several in a row ( 10, 100 ) => Std.rand2 => Std.mtof => float foo; // same 返回值做参数 Std.mtof( Std.rand2( 10, 100 ) ) => float foo;Overloading a function allows functions with the same name to be defined(定义) with different arguments. The function must be written in separate instances(实例) to handle the input, and the return type must agree(一致).
// funk( int ) fun int add(int x) { return x + x; } // funk( int, int ) fun int add(int x, int y) { return x + y; } // compiler automatically choose the right one to call add( 1 ) => int foo; add( 1, 2 ) => int bar;新闻热点
疑难解答