Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- /* Instead of Object*/
- typedef struct {
- int x;
- }Base;
- #define initBase {1}
- /* Instead of any of our classes that include a field of type Object*/
- typedef struct{
- Base b;
- int y;
- }Extension;
- #define initExtension(z) {initBase,z}
- /* Instead of sync that uses a pointer to Object */
- int doubleBase(Base *b){
- return 2*b->x;
- }
- /* Instead of SYNC that uses a pointer to some class that extends Object */
- #define DOUBLEBASE(a) doubleBase((Base *)a)
- /* Here we see how the type conversion works */
- int main(int argc, char* args[]){
- Extension e = initExtension(38);
- /* here you see the 2 level de-referencing e.b.x*/
- printf("%d %d\n",e.b.x,e.y);
- /* here you see the typecast at work! */
- printf("%d\n",DOUBLEBASE(&e));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement