Vector Help!

I wrote a program that goes through a maze. I am now trying to keep a list of the rooms in the order you went through and keep a second list in case you need to go back to where you were. For the first list, I'm trying to use a vector, but I keep getting an error. For the second part, I have no clue where to start. If anyone could help out that would be great! Thanks!


1
2
3


Last edited on
The problem begins here.

1
2
3
 vector<Node> rooms;
   rooms.push_back('A');


You are pushing a char data type into a vector which only allows Node data types. Now if you meant to insert the pointer variable "A". Then you need to change the data type of the vector to
1
2
vector<Node*>rooms;
rooms.push_back(A);

Now the vector only accepts pointers to Node.

You will have to do the same change for the iterator near the bottom.
Last edited on
When I do that, it prints the memory location of the pointer but not the value. How would I get it to show A,B,C or whatever room they are in? And if I do cout<<' ' << *current << ", ";
I get an error
Last edited on
You get an error because you are trying to display an entire object. You can either overload the ostream operator or you can pinpoint what exactly you are trying to display by doing this

 
cout<<current->getid()<<endl
When I do this, it prints out the same letter, which would be the ending room 'L' and but the 'L' prints for every step. How do I make it so it tracks each room and prints out the order you went in? So the current output looks like

"The path you took was: L L L L L L L L L L"

And I want it to be "The path you took was: A ..... L"
Last edited on
Topic archived. No new replies allowed.