nor*_*009 0 c++ stl segmentation-fault
我正在使用Visual Studio 2010 Beta 2(也尝试使用NetBeans),我在以下代码中遇到了分段错误:
// One of the @link s20_3_3_comparisons comparison functors@endlink.
template <class _Tp>
struct less : public binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; } //this is the problem line
};
Run Code Online (Sandbox Code Playgroud)
我不知道我的程序中有什么叫它,但我想知道.(我认为这是一张地图)有谁知道该怎么做,或者之前遇到过这个?
这段代码没有错; 问题在于你的代码正在调用它.(事实上,由于这是STL的一部分,因此该代码存在问题的可能性极小.)由于解除分配的内存,NULL指针或类似内容,可能会传递无效引用.
less默认情况下,对于std :: map,std :: set,以及我现在没想到的其他一些容器,所以你可以检查是否有任何容器,例如那些留下无效的容器值.
(实际上,最简单的方法是按照James McNellis的说法 - 在调试器中运行它并查看堆栈跟踪.)