gpt4 book ai didi

C++ 语法将 ColorA 拆分为 float ?

转载 作者:行者123 更新时间:2023-11-28 06:21:50 26 4
gpt4 key购买 nike

我记得我能做这样的事情,但我不记得是怎么做到的。我想从 ColorA 数据类型中提取 float ,用 C++ 执行此操作的最短语法是什么?

ColorA(r,g,b,a) = material.getAmbient();

最佳答案

如果您愿意提供 to_tuple 函数,则可以在此处使用 std::tie。一个元组转换函数 has problems有一个更糟糕的解决方法,所以这个解决方案很简单。

struct ColorA
{
float r, g, b, a;
auto to_tuple() const
{
return std::make_tuple(r, g, b, a);
}
};

int main()
{
float r, g, b, a;
ColorA color;
std::tie(r, g, b, a) = color.to_tuple();

return 0;
}

关于C++ 语法将 ColorA 拆分为 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29189389/

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