(const_cast<char*>和without有什么区别?
What's the difference between (const_cast<char*> and without?
我很难理解这两个命令之间的区别
char name[0x36];
sprintf_s(name, "Some Text (%d%% Water) [%dm]", amount, dist);
Drawing::RenderText(const_cast<char*>(name), screen, cfg.visuals.ships.textCol);
和
char name[0x36];
sprintf_s(name, "Some Text (%d%% Water) [%dm]", amount, dist);
Drawing::RenderText(name, screen, cfg.visuals.ships.textCol);
这是 RenderText 函数:
void xD::Renderer::Drawing::RenderText(const char* text, const FVector2D& pos, const ImVec4& color, const bool outlined = true, const bool centered = true)
{
if (!text) return;
auto ImScreen = *reinterpret_cast<const ImVec2*>(&pos);
if (centered)
{
auto size = ImGui::CalcTextSize(text);
ImScreen.x -= size.x * 0.5f;
ImScreen.y -= size.y;
}
auto window = ImGui::GetCurrentWindow();
if (outlined)
{
window->DrawList->AddText(nullptr, 0.f, ImVec2(ImScreen.x - 1.f, ImScreen.y + 1.f), ImGui::GetColorU32(IM_COL32_BLACK), text);
}
window->DrawList->AddText(nullptr, 0.f, ImScreen, ImGui::GetColorU32(color), text);
}
我正在使用 ImGui
What's the difference between (const_cast<char*> and without?
不同之处在于,在一种情况下转换是隐式的,而在另一种情况下转换是显式的。其他没有区别。
我很难理解这两个命令之间的区别
char name[0x36];
sprintf_s(name, "Some Text (%d%% Water) [%dm]", amount, dist);
Drawing::RenderText(const_cast<char*>(name), screen, cfg.visuals.ships.textCol);
和
char name[0x36];
sprintf_s(name, "Some Text (%d%% Water) [%dm]", amount, dist);
Drawing::RenderText(name, screen, cfg.visuals.ships.textCol);
这是 RenderText 函数:
void xD::Renderer::Drawing::RenderText(const char* text, const FVector2D& pos, const ImVec4& color, const bool outlined = true, const bool centered = true)
{
if (!text) return;
auto ImScreen = *reinterpret_cast<const ImVec2*>(&pos);
if (centered)
{
auto size = ImGui::CalcTextSize(text);
ImScreen.x -= size.x * 0.5f;
ImScreen.y -= size.y;
}
auto window = ImGui::GetCurrentWindow();
if (outlined)
{
window->DrawList->AddText(nullptr, 0.f, ImVec2(ImScreen.x - 1.f, ImScreen.y + 1.f), ImGui::GetColorU32(IM_COL32_BLACK), text);
}
window->DrawList->AddText(nullptr, 0.f, ImScreen, ImGui::GetColorU32(color), text);
}
我正在使用 ImGui
What's the difference between (const_cast<char*> and without?
不同之处在于,在一种情况下转换是隐式的,而在另一种情况下转换是显式的。其他没有区别。