Jump to content
  • Advertisement
Sign in to follow this  


This topic is 3788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering how should I let my gamestate classes change my vector. Here is my code so far.
	std::vector<baseGameState*> States;
	States.push_back(new MENU_STATE);

so should I try this? vector<int>::pointer ptrStates = &States.back(); [not sure if the .back() will work in this situation] and then just pass *ptrStates to my classes?

Share this post

Link to post
Share on other sites
What exactly is it you want to accomplish? Do you want to allow your classes to be able to push/pop states? Then you can just give them a reference (or pointer) to the state vector. Like this:

class A {
void do_something_which_causes_a_state_change(std::vector<baseGameState*> &gs) {
gs.push_back(new SOME_STATE);

int main() {
std::vector<baseGameState *> states;
A obj;
return 0;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!