title: abstract class and static methods
body: <p>I have an abstract class:</p>
  
  <pre><code>class A
  {
    public:
    bool loaded_;
    virtual int load() = 0;
  }
  </code></pre>
  
  <p>And several derived classes :</p>
  
  <pre><code>class B:public A
  {
    public:
    int load();
    static B&amp; instance();
  }  
  
  class C:public A
  {
    public:
    int load();
    static C&amp; instance();
  }  
  </code></pre>
  
  <p>The fact is that the code inside ::instance() methods is the same for each class :</p>
  
  <pre><code>static B&amp; B::instance()
  {
    static B instance_;
    if (!instance_.loaded_)
    {
      instance_.load();
      instance_.loaded_=true;
    }
    return instance_;
  }
  
  static C&amp; C::instance()
  {
    static C instance_;
    if (!instance_.loaded_)
    {
      instance_.load();
      instance_.loaded_=true;
    }
    return instance_;
  }
  </code></pre>
  
  <p>I would like to factorize this ::instance method, but given that it uses the virtual method ::load, i cannot define it in the class A. 
  Theoretically, i know it's weird since the class A should have 0 instance and B,C should have 1 instance but it also makes sense that this code should be factorized.</p>
  
  <p>How would you solve that problem ?</p>