#include <vector>
#include "Map.h"
#include "NPC.h"
using std::vector;
class Database
{
public:
vector<Map> maps;
vector<NPC> npcs;
Database()
{
// Populate the vectors and do initial stuff
}
};
Then elsewhere I do:
1 2 3 4 5 6 7 8
Database database;
// Let the game play for a while
do_stuff();
do_more_stuff();
// The database's members have now changed, time to save it into a file.
// This is where I have no idea what to do.
And additionally I need to be able to load this into an object again. SOmething like this?
1 2
Database database;
// magic function to make the new object equal to the one saved from earlier
It will obviously need to be modified to save all your classes members. You will probably want to make it a global function, so all instances of your class can be saved at once, rather than one at a time (if it were a member function). Also, I would suggest that you add error checking to these functions. (file.good(), file.is_open(), etc)
To your first question, yes. To your second, kindof. You will need to find a way to store all the elements of the vector, and then reload them. This can be done in a way similar to the first method I gave you.