source: CIVL/examples/experimental/oo.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 628 bytes
Line 
1//#include <assert.h>
2#include <stdio.h>
3
4typedef struct Point {
5 int (*getX)(void);
6 int (*getY)(void);
7 void (*setX)(int);
8 void (*setY)(int);
9} Point;
10
11Point make_point(int x0, int y0) {
12 int x, y;
13
14 int getX() { return x; }
15 int getY() { return y; }
16 void setX( int x1 ) { x=x1; }
17 void setY( int y1 ) { y=y1; }
18
19 x=x0;
20 y=y0;
21
22 Point result = {&getX, &getY, &setX, &setY};
23
24
25 return result;
26}
27
28int main() {
29 Point p1 = make_point(0,0);
30 Point p2 = make_point(1,2);
31 int k = p2.getY();
32
33 printf("k=%d\n",k);
34 p2.setY(17000);
35 k=p2.getY();
36 printf("k=%d\n",k);
37 //assert(k==0);
38}
Note: See TracBrowser for help on using the repository browser.