title: Factory pattern in C++. Issue of instantiation
body: <p>I have a small <code>Factory class</code> implemented in <code>Java</code>. Its minimized version looks like so:</p>
  
  <pre><code>interface MyClass{
      public void doSomething();
  }
  
  class Concrete_1 implements MyClass{
      private String field_1;
      Concrete_1(String _field_1){
          // ... initialization
      }
      public void doSomething(){
          // ... not so important
      }
  }
  
  class MyClassFactory{
      public static MyClass init(int idx, String val){
          Concrete_1 ex = null;
          switch(idx){
          case 1:
              ex = new Concrete_1(val);
              break;
          default:
              break;
          }
          return ex;
      }
      public static void main(String args[]){
          MyClass ex = MyClassFactory.init(1, "value"); // &lt;-- I like that
      }
  }
  </code></pre>
  
  <p>I like the way it works and especially the way, how I can instantiate particular objects, like:</p>
  
  <pre><code>MyClass ex = MyClassFactory.init(1, "value");
  </code></pre>
  
  <p>Now what I want is to implement the same thing in C++. I've seen some examples (including some threads at stackoverflow), but in all those examples they use an abstarct class (instead of an interface in my case of Java). And if memory servers me right, it is impossible to create instances of an abstract class. So, if we simply port the code above to C++ and use some abstract class instead of the interface, it will not work, because this is forbiden:</p>
  
  <pre><code>MyClass ex = MyClassFactory.init(1, "value"); // &lt;-- MyClass now is abstract
    // so this is illegal
  </code></pre>
  
  <p>My question is how can I do exactly the same thing in C++? Thanks!</p>