oop_in_c/Object.h

33 lines
578 B
C
Raw Normal View History

2012-04-30 18:59:30 +04:00
#ifndef __OBJECT_H__
#define __OBJECT_H__
2012-05-02 18:25:52 +04:00
typedef struct Object
2012-04-30 18:59:30 +04:00
{
2012-05-02 18:25:52 +04:00
struct Object_vtable
{
/* Object methods */
const char* (*type) ();
struct Object* (*clone) (const struct Object *this);
2012-05-02 18:25:52 +04:00
void (*destroy) (struct Object *this);
} *vtable;
2012-04-30 18:59:30 +04:00
2012-05-02 18:25:52 +04:00
} Object;
2012-04-30 18:59:30 +04:00
2012-05-03 16:03:48 +04:00
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);
}
2012-04-30 18:59:30 +04:00
#endif // __OBJECT_H__