C++ in G++ - Segmentation Fault when not using pointers

五迷三道 提交于 2019-12-03 21:43:27

Here's a general hint that will make your life a million times easier.

Compile this program with the "-g" and "-Wall" flags:

gcc -g -Wall foo.cpp

The "-g" adds debugging information. The "-Wall" spits out additional warnings when compiling. Then use the debugger:

gdb ./a.out

Hit run to start your program. Use bt to dump your call stack once your code crashes. You can then see exactly where the crash is happening in your code.

While you're at it, google "gdb tutorial". Spending an hour or two learning how to use gdb properly will pay itself back, with interest. I promise you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!