纯C实现c++类
//#include "stdafx.h"
/*
描述:纯c模拟类,纯c编写c++类,纯c实现c++类的简单范例,结构模拟类,struct 编写class.
c编写类是实现纯c编写com组件的基础。
*/
#include <stdio.h>
typedef struct _Vtbl
{
void (*AddRef)(struct CObject* obj,int);//所有的函数的第一个参数类似class的隐匿的this指针
void (*Release)(struct CObject* obj);
}Vtbl;//函数指针数组
typedef struct CObject
{
Vtbl vtbl;//函数指针数组指向成员函数
int a;
int b;
}Cobj;//结构模拟类的简单定义
void fun1(Cobj *obj,int count)//成员函数
{
obj->a+=count;
printf("CObject::a=%d\n",obj->a);
}
void fun2(Cobj *obj)//成员函数
{
obj->a--;
printf("CObject::a=%d\n",obj->a);
}
static Vtbl vt={fun1,fun2};//声明一个静态函数指针数组
int main()
{
Cobj obj;//定义对象
obj.vtbl=vt;
obj.a= 10;
obj.vtbl.AddRef(&obj,1);
obj.vtbl.Release(&obj);
return 0;
}
相关文档:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
&nbs ......
学了C然后C++,然后MFC/Windows,然后是C#,其中数据类型很多,由基本类型衍生的typedef类型也N多。熟知基本数据类型是我们正确表达实际问题中各种数据的前提,因此我分类总结了一下C/C++/Windows /C#基本数据类型,以便日后查阅。
ANSI C/C++基本数据类型:
Type
Size
......
//获得汉字的区位码
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes("啊");
int i1 = (short)(array[0] - ''\0'');
int i2 = (short)(array[1] - ''\0'');
//unicode解码方式下的汉字码
array = System.Text.Encoding.Unicode.GetBytes("啊");
i1 = (short)(arra ......