4 ms·
People did it in C way back, with usually structs containing their value and a table of functions associated with them (vtable). You can do "inheritance" by hav
by jrimbault 7y ago
People did it in C way back, with usually structs containing their value and a table of functions associated with them (vtable). You can do "inheritance" by having the parent struct be the first member of the child struct. You can do all sorts of fun stuff (composition is easy of course, injection also). The only thing of note, is that you can't "curry" the source, you'll always have to give the "source/this/self" object as an argument to the method. This isn't any different from how you could in python, for example, do : `"my string".split(" ")` or `str.split("my string", " ")`.
(just some fun little experiments I did last year
https://github.com/jRimbault/DataStructures/blob/master/lib/struct/String.h https://github.com/jRimbault/DataStructures/blob/master/lib/..., there isn't any vtable, but it does show a string "class/struct" with all private fields, and methods for creating, managing those objects)
- mistrial9 7y agoone-deep tables of function pointers with some kind of sensible model on why sets of function pointers are there.. many, many useful applications.
- marmaduke 7y ago> You can do "inheritance" by having the parent struct be the first member of the child struct. You can do all sorts of fun stuff I have done this, 'fun' is not how I describe the result to colleagues
- jrimbault 7y agoAlright, -fun +nightmarish. Still fun though.
- dboreham 7y agoAlso: in assembly, machine code.