I am trying to insert member data into a vector of structs, but I receive the errors:
1 2 3 4 5 6 7
main.cpp: In function âint main()â:
main.cpp:28: error: âclass std::vector<std::vector<MazeNode, std::allocator<MazeNode> >,
std::allocator<std::vector<MazeNode, std::allocator<MazeNode> > > >â has no member named ârowâ
main.cpp:29: error: âclass std::vector<std::vector<MazeNode, std::allocator<MazeNode> >,
std::allocator<std::vector<MazeNode, std::allocator<MazeNode> > > >â has no member named âcolumnâ
main.cpp:30: error: âclass std::vector<std::vector<MazeNode, std::allocator<MazeNode> >,
std::allocator<std::vector<MazeNode, std::allocator<MazeNode> > > >â has no member named âcellâ
So basically what I think is happening is that it will not allow me to access member data of a struct while it is in a vector, but I do not know a way around this. My question is, how do I insert struct member data into the vector?
Your problem isn't with the accessing code, but there. You define an 1array of an 2array of a 3vector of a 4vector of MazeNodes here, while you only want a vector of a vector of MazeNodes. Just drop the [r][c] at the end of the declaration and it will work perfectly fine. And btw: you would do it like that:
I can't help thinking he's trying to do something else though. There's technically nothing wrong with having a multidimentional array of vectors except in the way that he is trying to implement it (and the typedef, I have no idea what he's trying to accomplish there).
Computergeek01, thanks, I learned something new there even though it didn't directly apply to my question.
hanst99,
I tried my version and it seg faulted, so I pasted yours in and it works. I was figuring out why it worked, and thats why it took me so long to respond lol. But I understand why it works now, and why I didn't need the [r][c], I guess I put it there because I am new to vectors and was in the mindset of using arrays. Thanks a lot.
Yep, that's cause that's the vectors constructor arguments. And even then you couldn't have used it for a 2D vector (at least not in one line), so it doesn't really apply. If you wanted a constant size container, you might consider using a boost::array. (http://www.boost.org/doc/libs/1_46_1/doc/html/array.html )