As in the title, I am looking for some kind of data structure that will allow me to store in it any class that I need at that time. For instance:
Foo *foo = new Foo(); Bar *bar = new Bar(); someContainer.push_back( foo ); someContainer.push_back( bar ); someContainer.access( 0 )->doFooStuff(); someContainer.access( 1 )->doBarStuff();
Ideally, as I showed there, it would also allow me to access the contents and use their / etc functions.
I want one of them, because I am trying to create an โinvisibleโ memory management system that simply requires the class to inherit from my memory manager class and everything will work automatically.
Here is an example of how I want the code to look like this:
template< class T > class MemoryManaged { MemoryManaged() { container.push_back( this ); } void *operator new() { // new would probably be overloaded for reference counting etc. } void operator delete( void *object ) { // delete would most definitely overloaded } T &operator=( T &other ) { // = overloaded for reference counting and pointer management } static SomeContainer container; } class SomeClass : public MemoryManaged< SomeClass > { // some kind of stuff for the class to work }; class AnotherClass : public MemoryManaged< AnotherClass > { // more stuff! };
I hope that my code will help to understand what exactly I want to do. If someone knows some kind of already built data structure that would allow me to do this, that would be awesome. Otherwise, I'm currently working on creating some kind of zombie snake of a linked list class that uses template nodes to associate any type of class with any other type of class. I still donโt know how I earned, but I would like to be spared blood, sweat and tears (and hair) in order to understand how to make it work.
source share