Base class for class factories. More...
|Default constructor. |
Base class for class factories.
A class factory (or virtual constructor) is a class that can create instances of another class. Factory is a base class for such factories. When declaring an Array, Vec or Mat, a factory can be passed as an (optional) constructor argument:
By default, the factory (
f in the above examples) is not used at all! However, by overloading a help function called create_elements we can force Array/Vec/Mat to use the factory for element creation (instead of using the default constructor for the element type).
Here is an example that (partly) defines a user-defined numeric type My_Type, a corresponding factory My_Factory and a corresponding help function create_elements<My_Type> that will be used by Array, Vec and Mat for element creation.
For a more interesting example, see Fix_Factory.