单例 扩展
單例 C風格:
?
#include <stdio.h> #include <stdlib.h>struct {int *p;int n;}m; //匿名,單例struct data {int *p;int(*getdata)(struct data *p); }; int getdata(struct data *p) {static int *pdata = NULL;if(pdata!=NULL){return pdata;}else{pdata = malloc(4);*pdata = 10;return pdata;} }int main() {system("pause");return 0; }?
轉載于:https://www.cnblogs.com/bing-z/p/6272766.html
總結
- 上一篇: Spring依赖注入(DI)
- 下一篇: Zabbix每天流量统计脚本