gpt4 book ai didi

binary_function 中的 C++ 段错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:10:16 26 4
gpt4 key购买 nike

我正在使用 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
};

我不知道在我的程序中调用它的是什么,但我正在尝试找出答案。 (我认为这是一张 map )有没有人知道该怎么做,或者以前遇到过这种情况?

最佳答案

这段代码没有任何问题;问题出在调用它的代码中。 (事实上​​,因为这是 STL 的一部分,所以这段代码出现问题的可能性极小。)它可能由于释放内存、NULL 指针或类似原因而传递了无效引用。

less 默认用于 std::map , std::set ,可能还有一些我现在没有想到的其他容器,因此您可以检查是否有任何容器,例如那些留下了无效值的容器。

(不过,实际上,最简单的方法是按照 James McNellis 所说的那样 - 在调试器中运行它并查看堆栈跟踪。)

关于binary_function 中的 C++ 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3066621/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com