mardi 5 mars 2019

Need help understanding the use of C++11 initializer in Cisco DSLink Example

I am trying to understand this code snippet.

    stream->set_result(cisco::efm_sdk::UniqueActionResultPtr{
      new cisco::efm_sdk::ActionValuesResult{cisco::efm_sdk::ActionValuesResult(cisco::efm_sdk::ActionError)
                                               .add_value(false)
                                               .add_value("Could not set value")}});

Found in:

https://github.com/CiscoDevNet/kinetic-efm-cpp-sdk/blob/master/efm-cpp-sdk-1.0.15-ie4k-dslink-dev/examples/simple_responder/main.cpp

I understand that one object is instantiated using new cisco::efm_sdk::ActionValuesResult so that the object will survive outside of the scope of the lambda in which it is created. Or at least I believe that is why its being done.

But What I don't understand is why its being passed in an instance of itself when the docs don't specify that it has a constructor that can take such a parameter.

I would think that having the line like this:

    stream->set_result(cisco::efm_sdk::UniqueActionResultPtr{
      new cisco::efm_sdk::ActionValuesResult(cisco::efm_sdk::ActionError)
                                               .add_value(false)
                                               .add_value("Could not set value")});

Would actually make more sense. I've included a screen shot of the docs. And they are located here online:

https://github.com/CiscoDevNet/kinetic-efm-cpp-sdk/blob/master/efm-cpp-sdk-1.0.15-ie4k-dslink-dev/docs/index.html

Thanks in Advance, and my apologies if I am missing something basic.

-Robert Baindourov

Documentation

Aucun commentaire:

Enregistrer un commentaire