最終更新日時(UTC):
が更新

履歴 編集

function
<system_error>

std::error_category::コンストラクタ(C++11)

constexpr error_category() noexcept;            // (1) C++14
error_category(const error_category&) = delete; // (2)

概要

  • (1) : デフォルトコンストラクタ。error_categoryクラスのオブジェクトを構築する。
  • (2) : コピーコンストラクタ。コピー不可。これによって、ムーブコンストラクタも禁止される。

#include <iostream>
#include <system_error>
#include <string>

class user_defined_error_category : public std::error_category {
public:
  const char* name() const noexcept override
  {
    return "user defined error";
  }

  std::string message(int ev) const override
  {
    return "error message";
  }
};

const std::error_category& user_defined_category()
{
  static user_defined_error_category cat;
  return cat;
}

int main()
{
  const std::error_category& cat = user_defined_category();
  std::cout << cat.name() << std::endl;
}

出力

user defined error

バージョン

言語

  • C++11

処理系

参照