I have the following setup:
a class with a static member which is like:
static std::vector<int> m_Some[3];
The problem is, I cant m_Some[0].push_back(x) with it.
It triggers an error in <vector>‘s insert() and then in operator-.
But somehow the callstack is wrong for further actions so I cant see what’s real happening.
If I do m_Some[0].reserve(1); before push_back,
then I can make 1 push_back, but failed in the second push_back.
I have totally no idea why it can’t just push_back and has to reserve first…
And I event cant push_back more than the size I reserve.
I tried a local variable with same type of array, and it performs correctly with push_back.
I’m compiling using VS2008.
Anyone knows why? Thanks!
Are you calling push_back from a constructor of another static? In which case your vectors might not be constructed yet? Probably not, but there isn’t much to go on in the question. – J99 44 mins ago
Maybe he’s experiencing a static initialization order fiasco. – akappa 43 mins ago
@J99, yes I am calling it within a constructor of a global variable…! (declared in an .cpp) (but not static). I think that’s the problem, I’ll try to modify the code and see the result! – Marson Mao 33 mins ago
@J99 and akappa: Exactly the problem is, the vector initialzation is after my calling in the constructor…I’ll try to solve that problem then. Thanks!! (How to mark the comment as the answer?!) – Marson Mao 27 mins ago
@MarsonMao You cannot. Just answer your own question and mark it as accepted – akappa 8 mins ago
Above are the answers!
Thanks for the help 🙂