📄 test_example.c
字号:
/* ****************************** * Object Oriented Programming in C * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * For more information, please see the paper: * http://home.cern.ch/ldeniau/html/oopc/oopc.html * ****************************** */#include <stdio.h>/* Example of inheritance in OOPC: K --> J --> F --> G --> C --> A --> B --> H --> D --> E --> B --> I*/#include <example.h>intmain(void){ t_K *k = K.alloc(); printf("\nSize of objects:\n"); /* Output on 32-bits machine: */ printf("sizeof(t_A) = %d\n", sizeof(t_A)); /* sizeof(A) = 4 */ printf("sizeof(t_B) = %d\n", sizeof(t_B)); /* sizeof(B) = 4 */ printf("sizeof(t_C) = %d\n", sizeof(t_C)); /* sizeof(C) = 8 */ printf("sizeof(t_D) = %d\n", sizeof(t_D)); /* sizeof(D) = 4 */ printf("sizeof(t_E) = %d\n", sizeof(t_E)); /* sizeof(E) = 4 */ printf("sizeof(t_F) = %d\n", sizeof(t_F)); /* sizeof(F) = 4 */ printf("sizeof(t_G) = %d\n", sizeof(t_G)); /* sizeof(G) = 8 */ printf("sizeof(t_H) = %d\n", sizeof(t_H)); /* sizeof(H) = 8 */ printf("sizeof(t_I) = %d\n", sizeof(t_I)); /* sizeof(I) = 4 */ printf("sizeof(t_J) = %d\n", sizeof(t_J)); /* sizeof(J) = 24 */ printf("sizeof(t_K) = %d\n", sizeof(t_K)); /* sizeof(K) = 24 */ /* returns dynamic_cast<E*>(static_cast<A*>(k)) */ printf("\nDynamic cast example1:\n"); ooc_printObjInfo(stdout, dynamic_cast(super(k,J.m.G.m.C.m.A), E)); /* returns dynamic_cast<A*>(static_cast<E*>(k)) */ printf("\nDynamic cast example2:\n"); ooc_printObjInfo(stdout, dynamic_cast(super(k,J.m.H.m.E), A)); /* returns dynamic_cast<B*>(static_cast<A*>(k)) == NULL B appears twice in the class hierarchy */ printf("\nDynamic cast example3:\n"); ooc_printObjInfo(stdout, dynamic_cast(super(k,J.m.G.m.C.m.A), B)); /* Not present in C++ equivalent file */ printf("\nK object description:\n"); ooc_printObjInfo(stdout, k); delete(k); DEBUG_DISPMEM(stderr); return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -