为什么这个互斥锁无法进行constexpr构造?

huangapple go评论55阅读模式
英文:

Why can't this mutex be constexpr constructed?

问题

我遇到了错误信息:"初始化不是常量",在Microsoft Visual Studio Community 2022中,std::mutex是否具有constexpr构造函数?

英文:
#include <mutex>

int main()
{
    constexpr static std::mutex my_mooootex;
}

I get the error of:
"Initialization is not constant"

On Microsoft Visual Studio Community 2022. std::mutex has a constexpr constructor, doesn't it?

答案1

得分: 1

这是微软编译器中的一个缺陷。

您的代码是有效的。显示报告代码错误的任何编译器都是错误的。

英文:

It's a flaw in Microsoft's compiler.

Your code is valid. Any compiler reporting an error with the code you show is doing so incorrectly.

huangapple
  • 本文由 发表于 2023年2月19日 04:50:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75496315.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定