On Friday, September 25, 2015 at 11:56:46 AM UTC-4, Joel Andersson wrote:
>
> Hi,
>
> In C++ or in MATLAB I would use static member functions to keep the
> constructors nice and simple, e.g.
> class MyMatrix {
> public:
> static MyMatrix zeros(int n, int m);
> static MyMatrix ones(int n, int m);
> static MyMatrix eye(int n);
> ...
> };
>
> Which allows me to create class instances with an IMO natural syntax,
> which should also be relatively efficient due to return value optimization:
> MyMatrix x = MyMatrix::zeros(3,4);
>
>
In Julia, you can do the same thing, it is just spelled differently. You
could do
x = zeros(MyMatrix, 3, 4)
where you have defined
Base.zeros(::Type{MyMatrix}, m, n) = .....