Slide 6
Slide 6 text
C言語でも(頑張れば)OOPできる1
#include
struct user_data {
char name[20];
};
char *name(struct user_data *this) {
return this -> name;
}
char first(struct user_data *this) {
return this -> name[0];
}
struct user_class {
struct user_data obj;
char *(*name)(struct user_data *this);
char (*first)(struct user_data *this);
};
int main()
{
struct user_data this = { "foo" };
struct user_class u = { this, name, first };
printf("%s\n", u.name(&this));
printf("%c\n", u.first(&this));
}
1 普通はやらないと思う
6