in reply to Re^7: OO Getters/Setters
in thread OO Getters/Setters

C/C++ doesn't allow this, which means all those great tricks with closures in Perl and similar languages can't be done.

Pshaw. Go look in stdlib.h and figure out how qsort manages to call a function through a pointer to that function.

That is the key element to figuring out how to do anything that you can do with closures. What C won't do for you is bind an environment around a pointer to a function, or do your memory management for you. But nothing stops you from defining a struct that contains a pointer to a function and a pointer to an environment variable, and then a function that takes said struct and an argument, then calls the anonymous function passing in both environment and argument.

With some elbow grease you can then code by hand literally anything that you can do with closures. With the right macros you can hide most of the ugliness.

And if you don't want to do your own memory management, then don't.