lundi 17 août 2020

Is there any method to pass protobuf object to shared_ptr?

I want to copy protobuf msg "SmConfig" to an shared_ptr like below:

SignalMachine::SignalMachine(SmConfig* sm_config) {
  sm_config_ = std::make_shared<SmConfig>();
  sm_config_.CopyFrom(*sm_config);
}

class SignalMachine {
 private:
  std::shared_ptr<SmConfig> sm_config_;
}

Because I need to keep SmConfig(protobuf) in "class SignalMachine", I used the above method, is it reasonable? in fact, I did not find the corresponding description in the official document.

Aucun commentaire:

Enregistrer un commentaire