gpt4 book ai didi

c++ - 将 google::protobuf::RepeatedField 转换为 float

转载 作者:行者123 更新时间:2023-11-30 05:38:14 28 4
gpt4 key购买 nike

我正在使用 Google 的 Protobuf 创建一个名为 Foo 的 C++ 类,如下:

message Foo
{
optional int32 x = 1;
repeated float y = 2;
}

在创建的C++类中,这创建了一个成员变量y类型 const google::protobuf::RepeatedField<float> .现在,在我的 C++ 代码中,我想访问 xy Foo 实例的变量, 称为 foo .在这个例子中,y长度为一,即它包含一个 float :

int a = foo.x();
float b = foo.y();
float c = foo.y()[0];

在这里,第一行有效,但第二行和第三行都出现错误。我只是想获取存储在 y 中的这个 float 的值。 .

我应该怎么做?

谢谢!

最佳答案

你想要:

float b = foo.y(0);

(堆栈溢出提示我的回答太短...)

关于c++ - 将 google::protobuf::RepeatedField<float> 转换为 float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32874292/

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