title: Singleton approach on constructor
body: <p>I'm attempting to pass an object from one class constructor to another, but, it does not seem to want to work. Here is the code below:</p>
  
  <p>I have the following class:</p>
  
  <pre><code>class STFT {
  
      public:
  
        template&lt;typename Inverse&gt;
        STFT(Inverse begin, Inverse end, size_t x, size_t y, WindowType type)
        {
            switch(type) 
            {
                case 0: 
                this-&gt;w = Window(0, 100, this-&gt;w); // "0" is the type of window, 100 is the size, this-w is a reference to the object. 
                break;
  
                case 1:
  
                break;
            }         
        }
      protected:
         Window w;
  };
  </code></pre>
  
  <p>I have multiple classes <code>Hamming</code>, <code>Hanning</code> which all inherit from the class <code>Window</code> .. What I would like to do is have the constructor in <code>Window</code> determine which object to initialise..</p>
  
  <pre><code>Window(int theWindow, size_t size, Window&amp; w)
  {
     switch(theWindow)
     {
        case 0:
          w = new Barlett(100);
        break;
        //**
  }
  </code></pre>
  
  <p>But I'm getting the following error:</p>
  
  <p><code>no known conversion for argument 1 from 'Barlett*' to 'const Window&amp;'</code></p>
  
  <p>I think it's because I cannot convert <code>Window</code> to <code>Barlett</code> even though <code>Barlett</code> is inherited from <code>Window</code>.</p>
  
  <p>If anyone has any suggestions, it would be greatful :)</p>