18

12 年間の中断の後、C++ 開発に戻ります。私は JetBrains の CLion ソフトウェアを使用しています。これは、私のクラス設計で起こりうる問題について多くの情報を提供してくれるので素晴らしいです。クラスのコンストラクター throw ステートメントで表示される警告の 1 つは、次のとおり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;
} 

このコードはコンパイルされ、単体テストを実行できます。しかし、私はこの警告を取り除きたいと思っています (たとえコンパイルされたとしても、私が間違っていることを理解するために)。

4

1 に答える 1