小编Gui*_*oie的帖子

处理"抛出的异常类型不是无法复制构造"警告

经过12年的中断,回到C++开发.我正在使用JetBrains的CLion软件,因为它提供了很多关于我的课程设计可能出现的问题的输入.我在我的类'constructor throw语句中得到的警告之一是:Thrown exception type is not nothrow copy constructible.以下是生成此警告的代码示例:

#include <exception>
#include <iostream>

using std::invalid_argument;
using std::string;

class MyClass {
    public:
        explicit MyClass(string value) throw (invalid_argument);
    private:
        string value;
};

MyClass::MyClass(string value) throw (invalid_argument) {
    if (value.length() == 0) {
        throw invalid_argument("YOLO!"); // Warning is here.
    }

    this->value = value;
} 
Run Code Online (Sandbox Code Playgroud)

这段代码编译,我能够对它进行单元测试.但是我非常希望摆脱这个警告(为了理解我做错了什么,即使它编译了).

谢谢

c++ exception std c++11 clang-tidy

12
推荐指数
1
解决办法
3436
查看次数

使用 CLion/CMake/MSVC 2015 编译 WIN32 应用程序时出现链接错误

我无法使用 CLion 和 Visual Studio 2015 作为工具链编译简单的 WIN32 应用程序。这是我收到的链接器错误:

[ 50%] Linking CXX executable test-test.exe
MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
test-test.exe : fatal error LNK1120: 1 unresolved externals
LINK Pass 1 failed. with 1120
Run Code Online (Sandbox Code Playgroud)

以下是重现该问题的代码的最简化版本。它包含在这两个文件中:

有关我正在使用的工具的更多详细信息:

  • CLION 2018.1 EAP(最新版本)
    • 我还用以前的非 EAP 版本进行了测试,结果相同
    • CLion 的工具链架构设置为 x86_amd64
    • CLion …

c++ winapi cmake clion visual-studio-2015

4
推荐指数
1
解决办法
3180
查看次数

标签 统计

c++ ×2

c++11 ×1

clang-tidy ×1

clion ×1

cmake ×1

exception ×1

std ×1

visual-studio-2015 ×1

winapi ×1