S
Sarath
Dear All,
at the time class destruction, application error occurs. Seems the
heap was corrupted with the pop_back operation on empty vector.
the code failed to execute in Visual C++ 6 and 2008. but worked fine
in DevCPP. I admit that the pop function should check for empty
vector. but still the different behavior concludes, it's a bug in
Microsoft STL Implementation
template<class T>
class TestStack
{
public:
TestStack<T>() { _stack.reserve(1024); }
~TestStack<T>() { _stack.clear(); }
T pop()
{
T Obj = _stack.back();
_stack.pop_back();
return Obj;
}
void push( const T& element )
{ _stack.push_back( element ); }
bool clear( void ) { _stack.clear(); }
private:
deque<T> _stack;
};
int main( void )
{
TestStack<int> StackObj;
StackObj.pop();
StackObj.push( 10 );
StackObj.push( 20 );
StackObj.push( 30 );
StackObj.push( 40 );
return 0;
}
at the time class destruction, application error occurs. Seems the
heap was corrupted with the pop_back operation on empty vector.
the code failed to execute in Visual C++ 6 and 2008. but worked fine
in DevCPP. I admit that the pop function should check for empty
vector. but still the different behavior concludes, it's a bug in
Microsoft STL Implementation
template<class T>
class TestStack
{
public:
TestStack<T>() { _stack.reserve(1024); }
~TestStack<T>() { _stack.clear(); }
T pop()
{
T Obj = _stack.back();
_stack.pop_back();
return Obj;
}
void push( const T& element )
{ _stack.push_back( element ); }
bool clear( void ) { _stack.clear(); }
private:
deque<T> _stack;
};
int main( void )
{
TestStack<int> StackObj;
StackObj.pop();
StackObj.push( 10 );
StackObj.push( 20 );
StackObj.push( 30 );
StackObj.push( 40 );
return 0;
}