So it's perfectly possible to have multiple types of resource manager (menu, sound, etc etc) in the vector?
So it's perfectly possible to have multiple types of resource manager (menu, sound, etc etc) in the vector?
Sometimes I forget what I am doing when I enter a room, actually, quite often.
For some reason I'm having trouble with the syntax of creating an instance of a database class.
On creation I want them to push back resource managers of various types into the vector, for easy modification and all.Code:#ifndef DATABASE_H #define DATABASE_H #include <vector> #include "Resource_Manager.h" #include "Menu.h" template <typename T_> class Database { Database() { Data.push_back(Resource_Manager<Menu>); //Data.push_back(std::string Name); } private: std::vector<Resource_Manager<T_> > Data; }; #endif
Does this even work?
Sometimes I forget what I am doing when I enter a room, actually, quite often.
I think you're on the wrong track because I tried something like this myself before I really understood the inner workings of templates.
Templates are a compile time construct. They provide the compiler a set of instructions for writing certain types of functions and classes. For example, when you declare a std::vector<int>, the compiler goes to the std::vector template and essentially writes a new class called std::vector<int>. vector<int> and vector<float> and vector<yourclasshere> are all distinct data types, they are as unrelated as bool is to void*.
Templates are not a means of creating heterogeneous containers. The type of object that a vector holds is determined when you compile your program, and this can't be changed during runtime. If you want a collection of different objects, you need to have a common base class, Manager for example, that all the objects inherit from. Then you need a std::vector<Manager*>.
You could cheat and use a std::vector<void*>, but that would require you to track what kind of object is at each index, and that would get messy real fast.
In the long run, your best bet is to create a base class for all of your Managers and store a bunch of pointers to various Manager objects. If you set up the correct virtual functions in class Manager, this should provide all the functionality you need.
There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.
So then I guess all I can do is have the resource managers in the global scope? Oh wait, no I can make them initialize in the Manager object, kudos dude .
Sometimes I forget what I am doing when I enter a room, actually, quite often.