gpt4 book ai didi

c++ - 窄播有什么作用?

转载 作者:行者123 更新时间:2023-12-01 14:36:47 24 4
gpt4 key购买 nike

我看到一个使用 narrow_cast 的代码像这样

int num = narrow_cast<int>(26.72);
cout << num;

问题是我的编译器说:
'narrow_cast' was not decleared in this scope. 

我应该定义 narrow_cast我自己还是我用错了方法还是没有像 narrow_cast 这样的东西?

最佳答案

narrow_cast gsl真的是static_cast .但它更明确,您可以稍后搜索它。您可以查看 implementation你自己:

// narrow_cast(): a searchable way to do narrowing casts of values
template <class T, class U>
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
constexpr T narrow_cast(U&& u) noexcept
{
return static_cast<T>(std::forward<U>(u));
}
narrow_cast不是标准 C++ 的一部分。您需要 gsl编译并运行它。您可能错过了这一点,这就是它没有编译的原因。

关于c++ - 窄播有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58615926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com