Ask your own question, for FREE!
Computer Science 25 Online
OpenStudy (anonymous):

In C, how do I implement lists that can hold arbitrary objects, and then do stuff with those objects like in python? I'm thinking it's possible with a void* vector but I don't know what to do with all these void pointers :(

OpenStudy (espex):

You use struct to create the object that contains all the types you want, similar to a class and then you create an array of those objects.

OpenStudy (rsmith6559):

Since C++ is a superset of C and both Python and Java are written in C, it's certainly possible to create a List class. I'm attaching a PDF that I have on Object Oriented C. Your post jumps around a bit, but you'd have to implement a vector. Void pointers, or some type of typing at runtime, would seem the logical choice. Probably a good place to look would be if you could find the source code for C++'s List class.

OpenStudy (anonymous):

You could use an action script 2/3 array it doesn't give a darn about data type but my favorite is something else i find highly useful I store a string reference to an object because I can't store typed variables or objects in a array but I can store string references in an array usually on a FMS server (no necessary but useful) then I tell the client to get the "string object references" and build, rebuild, delete, destroy or modify the objects of interest. this method allows me manipulate objects in a very efficient manner because stage objects / objects don't have to be present lowering memory consumption I haven't checked allot for memory errors but from what tests I have done they are minimal and I see with my bare eyes minimal/zero impact on the CPU. Well as usual I don't have time/desire to write a book. FWIW. --calmchessplayer

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!