stl vector pop_back() crash

L

laniik

Hi. For some reason I am getting a crash on pop_back() and Im not sure
why.

sorry I cant post the whole code because the vector is used in a bunch
of places.

i have a

vector<bool> complete;

right before i pop back, i set the last element to overwrite on of the
ones in the array.

complete[j] = complete[complete.size()-1];
complete.pop_back();

the crash looks like:
unhandled exception: 0xC00000005 Access Violation reading 0x203f5a34

the size of complete before it crashes is 32, so it is not empty.

the code it crashes on is:
operator bool() const
{ // test if bit is set
return ((*_Getptr() & _Mask()) != 0);
}

at:

std::vector<bool,std::allocator<bool> >::reference::eek:perator bool()
Line 1030 + 0x12 C++

std::vector<bool,std::allocator<bool> >::reference::eek:perator=() Line
1006 +0x8 C++

std::_Copy_opt<std::vector<bool,std::allocator<bool>::iterator,std::vector<bool,std::allocator<bool>::iterator>(std::vector<bool,std::allocator<bool>::iterator_First={...},std::vector<bool,std::allocator<bool>::iterator_Last={...},std::vector<bool,std::allocator<bool>>::iterator_Dest={...},std::_Nonscalar_ptr_iterator_tag__formal={...})
Line 1022 + 0x26 C++

std::copy<std::vector<bool,std::allocator<bool>::iterator,std::vector<bool,std::allocator<bool>::iterator>(std::vector<bool,std::allocator<bool>::iterator_First={...},std::vector<bool,std::allocator<bool>::iterator_Last={...},std::vector<bool,std::allocator<bool>>::iterator_Dest={...})
Line 1040 + 0x3e C++

std::vector<bool,std::allocator<bool>::erase(std::vector<bool,std::allocator<bool>::iterator_Where={...})
Line 1562 + 0x42 C++

std::vector<bool,std::allocator<bool> >::pop_back() Line 1483 C++



If anyone has experenced anything like this before, or has some idea
what might be causing the crash, that would be great. thanks!

oliver
 
R

red floyd

laniik said:
[vector<bool> problem redacted]

I seem to recall that there was some sort of problem with the MS
implementation of vector<bool>. I know Dr. Plaugher reads this group.

What version of VC are you using?
 
L

laniik

hey. yea!

that seemed to be the problem. how bizarre, i changed it from a

vector <bool>

to a

vector<int>

and not only did it not crash anymore, but it fixed some wierd bugs
that were occuring as well.

words of caution: dont use vector<bool>!

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top