// # Include "stdafx. H"
/*
Description: pure C simulation class, pure C compiling C ++ class, simple example of pure C implementation C ++ class, structure simulation class, and struct compiling class.
C compiling class is the basis for compiling COM components in pure C.
*/
# Include <stdio. h>
Typedef struct _ vtbl
{
Void (* addref) (struct cobject * OBJ, INT); // The first parameter of all functions is similar to the hidden this pointer of class.
Void (* release) (struct cobject * OBJ );
} Vtbl; // array of function pointers
Typedef struct cobject
{
Vtbl; // a function pointer array pointing to a member function
Int;
Int B;
} Cobj; // simple definition of the structure simulation class
Void fun1 (cobj * OBJ, int count) // member function
{
OBJ-> A + = count;
Printf ("cobject: A = % d/N", obj-> );
}
Void fun2 (cobj * OBJ) // member function
{
OBJ-> --;
Printf ("cobject: A = % d/N", obj-> );
}
Static vtbl VT = {fun1, fun2}; // declare a static function pointer Array
Int main ()
{
Cobj OBJ; // define an object
OBJ. vtbl = Vt;
OBJ. A = 10;
OBJ. vtbl. addref (& OBJ, 1 );
OBJ. vtbl. Release (& OBJ );
Return 0;
}