title: C++ Programm calls superclass method instead of subclass method in factory pattern
body: <p>I'd like to build a factory for my Source-Plugins like that:</p>
  
  <pre><code>class PluginFactory {
  public:
      PluginFactory(){};
      virtual ~PluginFactory(){};
  
      static MySource* getSourceById(int id, ParameterList&amp; pList){
          switch (id){
              case 1:
                  return new StringSource(pList);
              default:
                  std::cout &lt;&lt; "Unknown PluginId!" &lt;&lt; std::endl;
                  return nullptr;
          }
  
      }
  };
  </code></pre>
  
  <p><code>MySource</code> cannot be abstract like usual in the pattern because it will later be used in a template class.</p>
  
  <p>When I call a method of the returned <code>MySource*</code> I get the method of the superclass <code>MySource</code> instead of the overridden method of the subclass <code>StringSource</code>.</p>
  
  <p>Any ideas how to fix this?</p>
  
  <p>EDIT:</p>
  
  <p>I declared the superclass method as vritual:</p>
  
  <pre><code>MySource{
      ...
      virtual std::streamsize read(char* s, std::streamsize n){
      ...
      }
  };
  </code></pre>
  
  <p>I added the override command to the subclasses' read-Method:</p>
  
  <pre><code>class StringSource: public MySource {
      ...
  std::streamsize read(char* s, std::streamsize n) override
  {
      ...
  }
  </code></pre>
  
  <p>};</p>
  
  <p>But it still uses the superclass method. There has to be another reason...</p>
  
  <p>Btw. I put the Source-Class into a boost::iostream::filtering_istream like this:</p>
  
  <pre><code>MySource* source = PluginFactory::getSourceById(1, pluginList[0].second);
  boost::iostreams::filtering_istream in;
  in.push(*source);
  </code></pre>
  
  <p>So I don't call the read-method myself.</p>