C++ game loading objects / global objects -
i still new c++ please forgive me if question unbearably obvious. (attempting) code rpg game. compiling nicely @ moment, have think how going load of objects (for unit classes, items etc) when game opens.
i have seen threads dll's , global objects using extern's in header files, wondered practical/efficient method? (as game large)
as stands, code clunky , not implemented ( did not think before trying use function declare objects in separate function , wonder why weren't accessible), should using extern rather having declare objects in main() in order instantiate them (see below).
#include <iostream> #include <string> #include "unit.h" #include "uclass.h" using namespace std; // seperate function @ program start load class list. void loadclass(uclass& obj) { obj.load("peasant"); } int main() { //load classes... cout << "creating peasant...\n"; uclass peasant; loadclass(peasant); cout << peasant.show() << endl; cout << "\ncreating unit...\n"; unit man; man.setlvl(); man.setclass(peasant); man.showinfo(); return 0; }
sorry again, first attempt @ multiple file project , thank in advance!
take std library have defined such structures example list. idea create list of objects load game, , while in resolving geometry or other logic want iterate through list. think start. if got concerns correctly.
Comments
Post a Comment