Thread: why would std::string assignment operator fail?
i call function
which looks thiscode:themap[x][y].moveuniton('m', c, "a merchant", unitpointer(&(merchantlist[merchantnum])));
and segmentation fault. gdb tells me problem bgdescription = description. bgdescription data member of tile. error is:code:void tile::moveuniton(char g, int c, string d, unitpointer unit) { bggraphic = graphic; graphic = g; bgcolorpair = colorpair; colorpair = c; bgdescription = description; description = d; occupyingunit = unit; }
the code worked fine until changed data member occupyingunit type merchant* unitpointer. in advance.code:#0 0x7ffff773019a ??() (/usr/lib/x86_64-linux-gnu/libstdc++.so.6:??) #1 0x7ffff77315c6 std::string::assign(std::string const&) () (/usr/lib/x86_64-linux-gnu/libstdc++.so.6:??) #2 0x4032ec tile::moveuniton(this=0x7ffffffa33c0, g=77 'm', c=5, d=..., unit=...) (/home/mike/desktop/klepto/tile.cpp:13) #3 0x40263c player::hiremerchant(this=0x7ffffffa2e80, c=5, themap=0x7ffffff1a300) (/home/mike/desktop/klepto/player.cpp:35) #4 0x404246 main(argc=1, argv=0x7fffffffe268) (/home/mike/desktop/klepto/main.cpp:265)
are running off end of array when index x , y?
if bgdescription not initialised string object, happen when try copy string (e.g. it's going try free old string data, garbage pointer).
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] why would std::string assignment operator fail?
Ubuntu
Comments
Post a Comment