In that, I set the variable roomRef in main, but when I call the valueSet() function, it says the variable is uninitialized. I've had this problem before and never really been sure how to resolve it. I tried making the function return a vector<room>, but I imagine that's not the best way to do it. Any help's appreciated. Thanks.Code:#include <iostream> #include <vector> using namespace std; struct room { int roomID; }; void valueSet(); int main() { vector<room> roomRef; valueSet(); int curRoom = 0; cout << roomRef[1].roomID; return 0; } void valueSet() { room Exterior; Exterior.roomID = 0; roomRef.push_back(Exterior); room Room1; Room1.roomID = 1; roomRef.push_back(Room1); room Room2; Room2.roomID = 2; roomRef.push_back(Room2); room Room3; Room3.roomID = 3; roomRef.push_back(Room3); room Room4; Room4.roomID = 4; roomRef.push_back(Room4); }



LinkBack URL
About LinkBacks



