经过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)
这段代码编译,我能够对它进行单元测试.但是我非常希望摆脱这个警告(为了理解我做错了什么,即使它编译了).
谢谢
我无法使用 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)
以下是重现该问题的代码的最简化版本。它包含在这两个文件中:
CMakeList.txt
cmake_minimum_required(VERSION 3.9.6)
add_executable(${PROJECT_NAME} WIN32 main.cpp)
Run Code Online (Sandbox Code Playgroud)主程序
#include <iostream>
int main(int argc, char **argv) {
std::cout << "HELLO WORLD!" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)有关我正在使用的工具的更多详细信息: