src/test/01-Basic/21.ck
raw| 1 | // 21.ck : classes inside classes |
| 2 | |
| 3 | // X |
| 4 | class X |
| 5 | { |
| 6 | float f; |
| 7 | int i; |
| 8 | } |
| 9 | |
| 10 | // Y has an X |
| 11 | class Y |
| 12 | { |
| 13 | X x; |
| 14 | } |
| 15 | |
| 16 | // foo that takes a Y |
| 17 | fun void foo( Y y ) |
| 18 | { |
| 19 | // assignment |
| 20 | 10.0 => y.x.f; |
| 21 | // assignment |
| 22 | 1 => y.x.i; |
| 23 | } |
| 24 | |
| 25 | // instantiate a Y |
| 26 | Y y; |
| 27 | |
| 28 | // call |
| 29 | foo( y ); |
| 30 | |
| 31 | // assign reference |
| 32 | y.x @=> X @ x; |
| 33 | |
| 34 | // test |
| 35 | if( x.f == 10.0 && x.i == 1 ) <<<"success">>>; |