Here is a sample of the pattern that we are using:
private:
static std::shared_ptr<Reporter>& defaultReporter()
{
static std::shared_ptr<Reporter> reporter = std::make_shared<DiffReporter>();
return reporter;
}
public:
static std::shared_ptr<Reporter> getDefaultReporter()
{
return defaultReporter();
}
static void setDefaultReporter( const std::shared_ptr<Reporter>& reporter)
{
defaultReporter() = reporter;
}Note the use of the reference (&) on the return type of the private method, and the addition of a getter and setter method.