我一直在尝试复制比https://github.com/google/flatbuffers/blob/master/samples/sample_binary.cpp
中的C ++示例更简单的内容。但是我在VS2017中遇到了一些编译错误
//auto pos = compare->pos;
//auto two = compare->deviceType;
//auto desc = compare->description;
如果我将其注释掉,它将编译并运行。如果没有,则出现以下错误:
Severity Code Description Project File Line Suppression State
Error C3867 'PNT::PseudoGPS::pos': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 50
Error C3867 'PNT::PseudoGPS::deviceType': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 51
Error C3867 'PNT::PseudoGPS::description': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 52
这是我的FBS对象的定义:
// Example IDL file for the PNT Schema
namespace PNT;
enum DeviceType:byte { IMU, VAN, GPS, MAGNAV, SOOP }
struct Vec3 {
x:float;
y:float;
z:float;
}
table PseudoGPS {
pos:Vec3;
deviceType:DeviceType = GPS;
description: string;
}
root_type PseudoGPS;
这是创建FB对象然后尝试访问事物的代码(我现在只是在探索,代码尚未完成)。
flatbuffers::FlatBufferBuilder builder(1024);
auto position = PNT::Vec3(4.0, 5.0, 6.0);
auto description = builder.CreateString("Magnetic Postion");
auto msg = PNT::CreatePseudoGPS(builder, &position, PNT::DeviceType_MAGNAV, description);
builder.Finish(msg);
uint8_t *buf = builder.GetBufferPointer();
int size = builder.GetSize();
auto compare = PNT::GetPseudoGPS(buf);
auto pos = compare->pos;
auto two = compare->deviceType;
auto desc = compare->description;
答案 0 :(得分:1)
compare->pos
是指访问器函数,请尝试附加()