0

语境化:

我正在研究一种面部识别算法,而 NIST 是试图标准化所有可用算法之间的测试、测量和比较的组织。为了进行测试和比较,我需要实现它们的接口,该接口在 FRVT Project中可用,更具体地说是在frvt11.h文件中。

frvt11.h这个问题的相关代码:

namespace FRVT {

//...A lot of code defining ReturnStatus, ReturnCode, etc.

/**
* @brief
* The interface to FRVT 1:1 implementation
*
* @details
* The submission software under test will implement this interface by
* sub-classing this class and implementing each method therein.
*/
class Interface {
public:
   virtual ~Interface() {}

   virtual ReturnStatus
    initialize(const std::string &configDir) = 0;

   /**
   * @brief
   * Factory method to return a managed pointer to the Interface object.
   * @details
   * This function is implemented by the submitted library and must return
   * a managed pointer to the Interface object.
   *
   * @note
   * A possible implementation might be:
   * return (std::make_shared<Implementation>());
   */
   static std::shared_ptr<Interface>
   getImplementation();
};
}

implementation.h我正在开发的实现的相关代码:

#include "frvt11.h"
using namespace FRVT;

struct Implementation : public Interface {

    ReturnStatus
    initialize(const std::string &configDir) override;

    static std::shared_ptr<Interface>
    getImplementation();
};

implementation.cpp我正在开发的实现的相关代码:

#include "implementation.h"
using namespace FRVT;

ReturnStatus
Implementation::initialize(
    const std::string &configDir) {
        return ReturnStatus(ReturnCode::Success," - initialize");
}

std::shared_ptr<Interface>
Implementation::getImplementation() {
    return (std::make_shared<Implementation>());
}

最后我的问题:

问题:如何实现 getImplementation() 以返回引用的“指向接口对象的托管指针”?

4

1 回答 1

1

我认为您可以执行以下操作:

std::shared_ptr<Interface> Implementation::getImplementation() {
  return std::make_shared<Implementation>();
}

int main() {
    auto interface = Implementation::getImplementation();
}

并且interface将是类型std::shared_ptr<Interface>。您可以进一步传递它。

于 2018-07-04T12:47:45.083 回答