Just define a zero-argument constructor:

type Point
  x::Float64
  y::Float64
  Point() = new()
end

p = Point(); # Will return uninitialized memory or #undef references 
depending on the field type

Note that this will override the default constructors; you'll need to 
explicitly add back the default Point(x,y) constructor.

On Friday, September 4, 2015 at 12:49:47 PM UTC-4, Ferran Mazzanti wrote:
>
> Dear all,
> I was wonder if it is possible to do in Julia what I can do in other 
> languages, such as define a user type, as for instance
>
> type Point
>   x::Float64
>   y::Float64
> end
>
> and then define a new varible of that type, but do not initialize it, as in
>
> z::Point
>
> which obviously doesn't work (unless in the local scope of a function, 
> with z being passed as an argument to the function).
>
> I ask because I am used to use pointers (in other languages), declare the 
> pointer, allocate room for the object, and  then
> use an instance of the object and initialize the different components in 
> the order I like. I mean to say something of the form, inventing my
> own instructions :)
>
> ype Point
>   x::Float64
>   y::Float64
> end
> z::Point
> allocate(z)
> z.y = 2.0
> z.x = 3.1
>
> In Julia the only way I know to initialize the object is to pass values to 
> it in exactly the same order the different fields appear in the
> type deffinition. Look as I have changed this order in my invented piexe 
> of code...
>
> Any hint appreciated.
>
> Thanks.
>

Reply via email to