proto复杂对象不能set

1.例子

message ProtoSrc
{
    message Feature
    {
        repeated float data = 1;
    }
    Feature feature = 1;
}

int main(int argc, char const *argv[])
{
  auto src = ProtoSrc();
  // ProtoSrc::Feature f;
  // error:no member named 'set_feature' in 'message::ProtoSrc'
  // src.set_feature(f); // 复杂对象不能set
  // 正确用法
  ProtoSrc::Feature& f = *src.mutable_feature();
  f.add_data(555);
  return 0;
}

 

posted @ 2024-04-27 20:39  lypbendlf  阅读(1)  评论(0编辑  收藏  举报