Thread: Creating a database

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    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.

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    For some reason I'm having trouble with the syntax of creating an instance of a database class.

    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
    On creation I want them to push back resource managers of various types into the vector, for easy modification and all.

    Does this even work?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #3
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    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.

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. literature database: help with planning
    By officedog in forum C++ Programming
    Replies: 1
    Last Post: 01-23-2009, 12:34 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Creating a database (inside a GUI)
    By goosematt in forum C Programming
    Replies: 7
    Last Post: 10-23-2003, 11:04 AM
  4. Creating a simple database: is my approach OK?
    By m712 in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2002, 02:27 AM
  5. creating a small database need some hints
    By asim0s in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2002, 10:44 AM