当我阅读Hypodermic的源代码时,我发现在其容器的构造函数中声明了一个空结构。我不明白它为什么这样做?
class Container : public std::enable_shared_from_this< Container >
{
private:
struct PrivateKey {};
public:
Container(const PrivateKey&,
const std::shared_ptr< IRegistrationScope >& registrationScope,
const std::shared_ptr< IRuntimeRegistrationBuilder >& runtimeRegistrationBuilder)
: m_registrationScope(registrationScope)
, m_runtimeRegistrationBuilder(runtimeRegistrationBuilder)
{
}
static std::shared_ptr<Container> create(const std::shared_ptr<IRegistrationScope>& registrationScope,
const std::shared_ptr<IRuntimeRegistrationBuilder>& runtimeRegistrationBuilder)
{
return std::make_shared<Container>(PrivateKey(), registrationScope, runtimeRegistrationBuilder);
}
// other code...
};
PrivateKey
是在上面的代码中定义的,我不明白它解决了什么问题。它似乎没有做任何事情。