cLion & cMake not debugning/printing 错误

cLion & cMake not debugning/printing an error

我刚了解到一个奇怪的问题。如果我 运行 Visual Studio 中的这段代码,我得到的输出是 NULL/error。但是当我 运行 在 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})

要获得反馈,您可以 运行 您的项目处于 'Debug' 模式。

您可以从菜单栏转到 运行 > 调试,或者只需按左上角的 'bug' 图标进入调试模式。

调试模式下的输出:EXC_BAD_ACCESS (code=1, address=0x0)

您还将获得相同的完整交互式堆栈跟踪。