src/test/01-Basic/26.ck
raw| 1 | // 26.ck : member functions that return object |
| 2 | |
| 3 | // delcare class |
| 4 | class X |
| 5 | { |
| 6 | int i; |
| 7 | } |
| 8 | |
| 9 | // declare another class |
| 10 | class Y |
| 11 | { |
| 12 | // declare a X as a member of Y |
| 13 | X x; |
| 14 | |
| 15 | // return x through a function |
| 16 | fun X foo() { return x; }; |
| 17 | } |
| 18 | |
| 19 | // instantiate a Y |
| 20 | Y y; |
| 21 | |
| 22 | // assign to y's x's field i |
| 23 | 1 => y.x.i; |
| 24 | |
| 25 | // get x through the function and test the value |
| 26 | if( y.foo().i != 1 ) <<<"fail">>>; |
| 27 | else <<<"success">>>; |