【发布时间】:2017-07-06 10:57:58
【问题描述】:
我刚刚了解到一个奇怪的问题。如果我在 Visual Studio 中运行此代码,我会得到 NULL/错误的输出。但是当我在 cLion 中运行时,我只是得到应用程序崩溃并且没有反馈。
VS 错误:
Exception thrown: read access violation.
this was nullptr.
这是我的配置:
main.cpp
#include <iostream>
using namespace std;
class testNothing {
public:
testNothing *test;
void donothing() { cout << test << endl; };
};
int main()
{
testNothing *hey = nullptr;
hey->donothing();
return 1;
};
CMakeList.txt
cmake_minimum_required(VERSION 3.8)
project(tests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
【问题讨论】:
-
当您似乎没有尝试过任何...时,不确定为什么将其标记为
debugging?打印运行时错误的程序不是“调试”;你需要自己调用它。 SO 不是调试服务。