Object Oriented Programming in ANSI C. Basic example showing how OOP can be realized on ANSI C for Figure class.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
578 B

#ifndef __OBJECT_H__
#define __OBJECT_H__
typedef struct Object
{
struct Object_vtable
{
/* Object methods */
const char* (*type) ();
struct Object* (*clone) (const struct Object *this);
void (*destroy) (struct Object *this);
} *vtable;
} Object;
static inline const char* Object_type (const Object *this)
{
return this->vtable->type ();
}
static inline Object* Object_clone (const Object *this)
{
return this->vtable->clone (this);
}
static inline void Object_destroy (Object *this)
{
this->vtable->destroy (this);
}
#endif // __OBJECT_H__