Prev | Index | Next |
Functions in C* have a new syntax:
function main() => int { ... }
This syntax is both more readable and easier to compile than the C++ syntax. The => int
clause specifies the return type of the function. To specify void functions (also called procedures), just leave off that clause:
function f();
Many operators in C* are user-definable. To define an operator, use the same syntax as for functions, except replace "function" with "operator":
operator *(int n, char c) { ... }
This defines the multiplication operator for an int and a char (perhaps to return a string containing n copies of c). To call it, you would use the * operator with the appropriate argument types:
3 * 'c';
Overloading of functions is allowed in C* as well. The overloading algorithm to determine which function is called for a given call site is as follows:
Prev | Index | Next |