I’ve tried to SSCE my problem as best possible, but it involves mulitple objects defined in C++. They are simple, though – I think its best if I share my code before explaining further:
#include <iostream>
#include <vector>
struct Cell {
bool visited;
Cell():visited(false) {}
void setVisited(bool val) {visited = val;}
bool beenVisited() {return visited;}
};
struct Vector2D
{
int size;
std::vector<Cell> myVector;
Vector2D(int n): size(n), myVector(n*n) {}
Cell& getAt(int x, int y) {return myVector[((x * size) +y)];}
};
int main()
{
Vector2D vec = Vector2D(1);
Cell cell= vec.getAt(0,0);
cell.setVisited(true);
cell = vec.getAt(0,0);
if (cell.beenVisited() == false)
std::cout << "Why is this not true like I set it a moment ago?\n";
}
I apologize sincerely for all of this, but it is needed to make the point. As you can see, I getAt() what I think to be Cell object, set its visited instance data to true, and then switch off to another cell. Why, then, when i come back to that same cell, find that the visited value is false instead of true?! It’s like it isn’t registering my private data change!
What is the best way to do this?
Thanks
copy of object.
Use
or simply
EDIT.
This code should works.
http://liveworkspace.org/code/53634eda052a07885d4e6c062a0fd302