クラスを作る


#include
#include

typedef struct _Name {
char *first;
char *last;
void (*getName)(void*, char*);
} Name;

void _getName(void *_this, char *name) {
Name *this = _this;
strcpy(name, this->first);
strcat(name, ", ");
strcat(name, this->last);
}

void new_Name(Name *this, char *first, char *last) {
this->first = first;
this->last = last;
this->getName = _getName;
}

int main() {
Name clazz;
char name[256];

new_Name(&clazz, "Taro", "Yamada");
clazz.getName((void*)&clazz, name);
printf("%s\n", name);

return 0;
}