class Base {
public:
static std::unique_ptr<Base> CreateBase();
}
class Factory {
public:
static std::unique_ptr<Base> CreateBase();
}
我们可以在基类中声明工厂方法,也可以创建一个单独的类并在其中编写工厂方法。哪个更好,为什么?
最佳答案
都没有。
您还可以将工厂声明为自由函数 std::unique_ptr<Base> CreateBase()
又名 std::make_unique<Base>
关于c++ - 在基类中编写工厂方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59037968/