Denver Toha Asked:2023-06-09 20:37:32 +0000 UTC2023-06-09 20:37:32 +0000 UTC 2023-06-09 20:37:32 +0000 UTC 为什么不能创建一个 constexpr std::error_category,因为这个类有一个 constexpr 构造函数? 772 std::error_category 有一个 constexpr 构造函数,但它是一个抽象类。因此,它的孩子不能由 constexpr 创建。那么为什么要使用 error_category constexpr 构造函数呢? c++ 2 个回答 Voted Harry 2023-06-09T20:49:35Z2023-06-09T20:49:35Z 好吧,例如,在 VC++ 中,您可以轻松地... #include <string> #include <iostream> #include <iomanip> using namespace std; class concrete: public std::error_category { public: constexpr concrete():std::error_category(){} const char* name() const noexcept { return "concrete"; } std::string message( int ) const { return "concrete"s; }; }; int main() { constexpr concrete c; } Best Answer Jango 2023-06-10T14:47:34Z2023-06-10T14:47:34Z 查看这些链接解释原因 https://github.com/microsoft/STL/issues/1116 https://www.cppstories.com/2021/constexpr-virtual/
好吧,例如,在 VC++ 中,您可以轻松地...
查看这些链接解释原因
https://github.com/microsoft/STL/issues/1116
https://www.cppstories.com/2021/constexpr-virtual/