Writing to two dimensional vector within structure

I want to write to a two dimensional vector that is part of a structure, it is of type boolean, and also, I am using SFML in my project and would like to know how to call functions like sprite.setTexture(texture) , I am just learning about vectors.
Thanks!
Structure:
1
2
3
4
5
6
7
8
9
10
  struct maps{
    int width;
    int height;
    Texture Entities;
    Texture Wall;
    Texture Barrier;
    vector<vector<Sprite> > all;
    vector<vector<bool> > canGo;

};

And this is just a snippet of my code:
1
2
3
4
5
6
7
8
9
10
maps rtrn;
for (int i = 0; i != width_; ++i)
    {
         for (int j = 0; j != height_; ++j)
         {
                cout << "ERR";
            rtrn.canGo[i][j] = true;

         }
    }
Last edited on
You can do it pretty much the same way you might expect. Based off your code:
1
2
3
4
5
6
maps rtrn;
for (int i = 0; i < rtrn.all.size(); ++i) {
    for (int j = 0; j < rtrn.all[i].size(); ++j) {
        rtrn.all[i][j].setTexture(texture);
    }
}


It may interest you to know, however, that there is such thing as a 'range-based for' loop, which will (usually) result in more readable code:
1
2
3
4
5
6
7
// (pretty much) equivalent to the above code
maps rtrn;
for (auto&& v : rtrn.all) {
    for (auto&& sprite : v) {
        sprite.setTexture(texture);
    }
}
Oh, ok, so the boolean canGo, would be like this?
1
2
3
4
5
for (auto&& v : rtrn.canGo) {
    for (auto&& boolean : v) {
        boolean = true;
    }
}
@TwilightSpectre

Thanks for the forward reference here:

for (auto&& v : rtrn.all) {

http://en.cppreference.com/w/cpp/language/range-for


++ThingsLearnt;


Regards :+)
Last edited on
Ok, so I followed all that, and I have been able to compile and run the project, but it will not display anything, this is more SFML based, but can someone still help me?
I have 3 files,
main.cpp
conector.h
getRect.cpp

getRect is kind of a library, or list, where I look up an IntRect that is relative to my texture,
connector.h is included in both main.cpp, and getRect.cpp.
Here are links to my code:
Main:
http://pastebin.com/DqEn6CVU
conector:
http://pastebin.com/6qHCRXK9
GetRect:
http://pastebin.com/X515Ei3T
Thanks for the previous help too!
Last edited on
So, I kept trying and still couldn't find an answer.
Topic archived. No new replies allowed.