Sundar R :julia: · @Sundar
28 followers · 22 posts · Server julialang.social


2022-11-28

Say you define a type
```
struct Point2D
x::Int
y::Int
end
```
then x and y are the "fields" of this struct. `fieldnames(Point2D)` returns `(:x, :y)`.

If you define `mypt = Point2D(4, 8)`, then
`mypt.x` calls `getproperty(mypt, :x)` (see prev. post),
which by default calls `getfield(mypt, :x)`,
which is automatically defined by to return `x`'s value.

(contd. from previous: julialang.social/@Sundar/10941
as part 2 of )

#juliatipoftheday #juliabeginners #julialang #fieldsandproperties

Last updated 3 years ago