1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | #include <assert.h>
|
|---|
| 2 |
|
|---|
| 3 | typedef struct Point {
|
|---|
| 4 | int (*getX)(void);
|
|---|
| 5 | int (*getY)(void);
|
|---|
| 6 | void (*setX)(int);
|
|---|
| 7 | void (*setY)(int);
|
|---|
| 8 | } Point;
|
|---|
| 9 |
|
|---|
| 10 | Point make_point(int x0, int y0) {
|
|---|
| 11 | int x, y;
|
|---|
| 12 |
|
|---|
| 13 | int getX() { return x; }
|
|---|
| 14 | int getY() { return y; }
|
|---|
| 15 | void setX( int x1 ) { x=x1; }
|
|---|
| 16 | void setY( int y1 ) { y=y1; }
|
|---|
| 17 |
|
|---|
| 18 | Point result = {&getX, &getY, &setX, &setY};
|
|---|
| 19 |
|
|---|
| 20 | return result;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | int main() {
|
|---|
| 24 | Point p1 = make_point(0,0);
|
|---|
| 25 | Point p2 = make_point(1,2);
|
|---|
| 26 |
|
|---|
| 27 | assert(p1.getX()==0);
|
|---|
| 28 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.