A
Aniruddha
How do I simulate(to a minimal extent) the
notion of classes and methods in C ?
notion of classes and methods in C ?
How do I simulate(to a minimal extent) the
notion of classes and methods in C ?
Nils said:struct my_class {
int blah;
};
my_class *new_myclass() {
struct my_class *this;
this = malloc(sizeof *this);
/* error handling here */
}
void delete_myclass(struct my_class *this) {
free(this);
}
void my_method(struct my_class *this) {
do_something_to(this);
}
struct my_class *new_myclass() {
doh.
return this;
You may want to add function pointers to struct my_class to
emulate the C++ notion even better.
Nils said:Depending on the definition of "minimal extent". But for every step
towards "real" classes it becomes more complex and the OP should consider
actually using C++ instead.
Aniruddha said:How do I simulate(to a minimal extent) the
notion of classes and methods in C ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.