My program has a class with a vector of Level
objects named levels
. In a member function there is this line:
levels.push_back(level::Level());
I made several changes to my program today, and that line of code started segfaulting:
0x0804d248 in void std::vector<yarl::level::Level, std::allocator<yarl::level::Level> >::emplace_back<yarl::level::Level>(yarl::level::Level&&) (this=0x0,
__args#0=...) at /usr/include/c++/4.4/bits/vector.tcc:93
93 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
I thought that the Level
object may have somehow become corrupt, so I declared it outside the function call so I could inspect it in gdb, like this:
level::Level foo();
levels.push_back(foo);
Turns out this doesn't compile. It g++ gives two errors I haven't seen before:
error: invalid conversion from 'level::Level (*)()' to 'int'
error: initializing argument 1 of 'level::Level::Level(int, int, int)'
Now, Level
's constructor takes three integer parameters, each with default values. I thought it might have been complaining that I hadn't passed those three parameters, even though they have defaults, so I changed the first line to pass the value of the defaults:
level::Level foo(1, 100, 100);
This now compiles, and still segfaults, but does so at a different spot (although an identical test):
0x0804c699 in std::vector<yarl::level::Level, std::allocator<yarl::level::Level> >::push_back (this=0x0, __x=...) at /usr/include/c++/4.4/bits/stl_vector.h:735
735 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
I realize this is too little code to expect you guys to be able to solve my problem, but perhaps someone could tell me a little more about what these errors mean? Those g++ errors especially; I don't know why it wouldn't accept an empty Level
constructor given that all its parameters are default, and I have no idea what the (*)()
part of the error means (it makes the error a very frustrating one to google).