is there way can call function (somewhere initialized) that:
mystruct.foo(); allowing foo() access mystruct structure inside.
my goal use bit of object oriented programming in c , allow foo access members, part of mystruct structure.
there no way make happen magically, thing can think of this
#include <stdio.h> #define declare_class_method(class, name, ...) \ (*name)(class *this, __va_args__) typedef struct class class; struct class { int declare_class_method(class, method, int value); }; int method(class *this, int value) { fprintf(stderr, "%p: %d\n", (void *) this, value); return 0; } int main(void) { class instance; instance.method = method; instance.method(&instance, 9); return 0; } but can see must pass instance method, not happen automatically in oo language c++.
Comments
Post a Comment