title: How to allow a class to be created by another without using 'friend' but allow inheritence?
body: <p>I have three classes in total for my game engine, an abstract IComponent class in which all components inherit from it, a component class (for this example I will use RenderComponent), and a ComponentManager. I want the ComponentManager class to be able to use the constructor of RenderComponent, but I don't want any other classes to create an instance of RenderComponent, but I don't want to use 'friend' since I want customer user components to inherit from IComponent and automatically be used in the ComponentManager without being allowed to instantiate their own. The code example shows vaguely the behavior I want to occur:</p>
  
  <pre><code>class GameObject;
  
  class IComponent
  {
      private:
          IComponent() { }
          ~IComponent() { }
      public:
          GameObject* Parent;
  }
  
  class RenderComponent : IComponent
  {
      public:
          RenderComponent() { }
          ~RenderComponent() { }
  }
  
  class ComponentManager
  {
      public:
          ComponentManager() { }
          ~ComponentManager() { }
  
          // normally this would be a template function, but for the sake of this example I will directly use RenderComponent
          RenderComponent* CreateComponent()
          {
              // this would not throw a compiler error
              return new RenderComponent();
          }
  }
  
  int main()
  {
      ComponentManager manager;
  
      // even though the constructor of RenderComponent is public, this would throw an error
      RenderComponent* render = new RenderComponent();
  
      // this however would work perfectly fine
      RenderComponent* render = manager.CreateComponent();
  
  }
  </code></pre>
  
  <p>To reiterate, I want it so that there is minimal user effort to creating components. The other option of course is to have the constructor for both public but have it so that although you can create a component wherever you want, it will be useless.</p>