编译器错误C2398缩小转换

发布于 2025-01-26 09:57:56 字数 561 浏览 4 评论 0原文

因此,我已经看过几次这个任务,并且尝试用static_cast(width)和static_cast(高度)包装它,但是它只是产生相同的错误,我不太确定为什么在我看来它int float甚至不需要一个缩小转换。我目前正在学习IMGUI,并且在编译时会遇到此错误 错误C2398元素'1':从“ const int”到“ float”的转换需要缩小转换

这是我的代码

constexpr int WIDTH = 500; 
constexpr int HEIGHT = 300;

}
//it is referenced later in this line in a different file that DOES include the header

void gui::Render() noexcept
{
ImGui::SetNextWindowSize({ WIDTH, HEIGHT });
}

//I have attempted to do a simple float conversion but it still screams at me with the same error

So I have seen this quest a few times and I have tried wrapping it with static_cast(WIDTH) and static_cast(HEIGHT) however it just produces the same error and I am not too sure why it seem to me int to float shouldnt even need a narrowing conversion. I am currently learning ImGui and am getting this error when i compile
Error C2398 Element '1': conversion from 'const int' to 'float' requires a narrowing conversion

This is my code

constexpr int WIDTH = 500; 
constexpr int HEIGHT = 300;

}
//it is referenced later in this line in a different file that DOES include the header

void gui::Render() noexcept
{
ImGui::SetNextWindowSize({ WIDTH, HEIGHT });
}

//I have attempted to do a simple float conversion but it still screams at me with the same error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文