Factory Method in C++

A factory method is a static method of a class that returns an object of the class’s type. But unlike a constructor, the actual object it returns might be an instance of a subclass. Another advantage of a factory method is that it can return existing instances multiple times.

Also, the factory method can be defined in the base class, or, in a separate factory class.