【发布时间】:2015-09-21 09:08:47
【问题描述】:
我对 C/C++ 中的指针世界很陌生,所以这对你来说可能是一个很简单的问题:
以下C++代码正常工作
#include <iostream>
int main()
{
int theInt = 1337;
int & theReference = theInt;
int * thePointer = &theInt;
std::cout << "int: " << theInt << "\n";
std::cout << "referenz: " << theReference << "\n";
std::cout << "pointer: " << *thePointer << "\n";
std::cout << "pointer: " << *thePointer << "\n";
//std::cout << "foo" << "\n";
return 0;
}
但在更改时停止工作
//std::cout << "foo" << "\n";
到
std::cout << "foo" << "\n";
.
“停止工作”是指:“被我的诺顿安全系统阻止为潜在威胁”(如果有帮助,将导致返回代码“0x76F531AF”)。由于诺顿通常不会干扰我的编程,我假设在 cout 中双重使用 int 指针会导致段错误......
感谢您的帮助!
PS:
我在 Windows 8.1 上使用 Code::Blocks 和来自 TDM-GCC(版本 4.7.1,32 位)的 GCC 编译器和 GDB 调试器。
编辑:删除指针 -> 问题仍然存在。
【问题讨论】:
-
delete thePointer仅在您使用int *thePointer = new int时才需要,因此请删除它 -
我删除了那行,问题依旧。
-
您是否正在运行旧版本的输出二进制文件?您是否检查了发布/调试配置等?您的 IDE 是否有“干净”命令?我问这个是因为在您删除
delete thePointer后您的代码没有任何问题。 -
“被我的诺顿安全系统阻止为潜在威胁”因为这意味着“为什么软件 X 是垃圾”,这确实是一个话题。你希望我们告诉你什么?您已经知道您拥有的特定 Norton Security 安装是无用的垃圾。您可以忍受疼痛并继续使用它,或者摆脱它。您的选择。
-
@KubaOber 实际上,我认为诺顿的干预是指针误入歧途的标志,所以它并不是真正的:“为什么诺顿不能正常工作”。
标签: c++ pointers segmentation-fault cout norton