c++: gcc 4.2.1给出的程序会出现分段错误,而不是在linux上
C++: gcc 4.2.1 gives program which segfaults, not on linux
下面这个简单的程序在我的mac (Lion)运行gcc 4.2.1时出现了分段错误:
#include <iostream>
using namespace std;
struct A{
friend std::ostream& operator << (std::ostream& os, const A& a) {
os << 3 << endl;
}
};
template <typename T>
T f() { return T();}
int f() { return 2;}
int main() {
cout << f() << endl;
A a= f<A>();
cout << a << endl;
}
当我运行程序时,我得到:
./a.out
2
3
Segmentation fault: 11
当我执行堆栈跟踪时,我得到:
(gdb) run
Starting program: a.out
unable to read unknown load command 0x24
unable to read unknown load command 0x26
2
3
Program received signal SIGSEGV, Segmentation fault.
0x00007fff8b84fa49 in ?? ()
(gdb) bt
#0 0x00007fff8b84fa49 in ?? ()
#1 0x00007fff665c1ae8 in ?? ()
#2 0x0000000000000000 in ?? ()
回溯没有有用的信息(有人知道为什么吗?)这是
让我们看得更清楚些
(cout << a) << endl;
你在你的operator<<
中忘记了一个return
相关文章:
- 在某些循环内使用vector.push_back时出现分段错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 当我的阵列太大时出现分段错误
- 分段错误当我试图运行程序时出错
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 尝试使用集合函数时出现分段错误
- 我无法缩小此分段错误的原因
- g++的分段错误(在NaN上使用to_string两次时)
- 为什么我使用 std::copy() 收到运行时错误(分段错误)?
- 为什么我的代码包含错误分段错误(核心转储)?
- 为什么会出现此错误?- 分段错误(核心转储)
- 意外的运行时错误(分段错误)
- C++将文本文件读入数组,运行错误:分段错误
- mmap 错误:分段错误/指针无效错误
- 在我的代码中找不到错误....分段错误
- 错误:分段故障(核心转储)阵列
- 用string.h将错误分段到队列中
- c++字符串流转换错误:分段错误
- 为什么我的代码显示错误分段错误(核心转储)