C++ C++;接口';s工厂功能的实现

C++ C++;接口';s工厂功能的实现,c++,shared-ptr,biometrics,make-shared,facial-identification,C++,Shared Ptr,Biometrics,Make Shared,Facial Identification,语境化: 我正在研究一种面部识别算法,NIST是一家试图将所有可用算法之间的测试、测量和比较标准化的组织。为了进行测试和比较,我需要实现它们的接口,该接口在中提供,更具体地说是在文件中 frvt11.h此问题的相关代码: namespace FRVT { //...A lot of code defining ReturnStatus, ReturnCode, etc. /** * @brief * The interface to FRVT 1:1 implementation * * @

语境化:

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

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();
};
}
名称空间FRVT{
//…定义ReturnStatus、ReturnCode等的大量代码。
/**
*@brief
*FRVT 1:1实现的接口
*
*@详情
*测试中的提交软件将通过以下方式实现此接口:
*对该类进行子分类并实现其中的每个方法。
*/
类接口{
公众:
虚拟~Interface(){}
虚拟返回状态
初始化(const std::string&configDir)=0;
/**
*@brief
*方法返回指向接口对象的托管指针。
*@详情
*此函数由提交的库实现,必须返回
*指向接口对象的托管指针。
*
*@注
*一种可能的实施方式可能是:
*返回(std::make_shared());
*/
静态std::共享的ptr
getImplementation();
};
}
实施。h我正在制定的实施相关代码:

#include "frvt11.h"
using namespace FRVT;

struct Implementation : public Interface {

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

    static std::shared_ptr<Interface>
    getImplementation();
};
#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>());
}
#包括“frvt11.h”
使用名称空间FRVT;
结构实现:公共接口{
返回状态
初始化(const std::string和configDir)覆盖;
静态std::共享的ptr
getImplementation();
};
实施。cpp我正在制定的实施相关代码:

#include "frvt11.h"
using namespace FRVT;

struct Implementation : public Interface {

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

    static std::shared_ptr<Interface>
    getImplementation();
};
#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>());
}
#包括“implementation.h”
使用名称空间FRVT;
返回状态
实现::初始化(
const std::string和configDir){
ReturnStatus(ReturnCode::Success,“-initialize”);
}
std::共享的ptr
实现::getImplementation(){
返回(std::make_shared());
}
最后,我的问题是:

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();
};
}

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

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

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

int main() {
    auto interface = Implementation::getImplementation();
}
std::shared_ptr实现::getImplementation(){
返回std::make_shared();
}
int main(){
自动接口=实现::getImplementation();
}

接口
的类型将为
std::shared\u ptr
。你可以进一步传递它。

请在StasOffFuff.com上的每个问题一个问题。请考虑代码审查SE。避免交叉发布。@SamVarshavchik所有5个问题都与同一上下文相关。为什么要复制上下文5次?对不起,但你似乎连所有的东西都没看。无论如何谢谢你。我也没有。你应该考虑一下@SamVarshavchik说的话。照目前的情况,这对于SO格式来说太宽泛了。建议是相关的,因为这就是模型和方法。NIST的评论建议在实现中使用make_共享。为什么建议在实现中使用shared_ptr?这是一种更好的方法吗?前者只是更短而已。))