Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.36 KB

File metadata and controls

51 lines (38 loc) · 1.36 KB

CodingPatterns

Contents

Static variables for header-only releases

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

snippet source / anchor

Note the use of the reference (&) on the return type of the private method, and the addition of a getter and setter method.


Back to User Guide