You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An example is given that it is possible to have a custom method inside a struct like this:
struct Person
name::String
age::Int
occupation::StringfunctionPerson(name::String, age::Int, occupation::String)
new(name, age, occupation)
endfunctionintroduce(p::Person)
println("Hi, my name is $(p.name) and I am a $(p.age)-year-old $(p.occupation).")
endend
p1 =Person("Alice", 25, "Software Engineer")
p1.introduce()
However, this code will not run and it should be changed to this:
struct Person
name::String
age::Int
occupation::StringfunctionPerson(name::String, age::Int, occupation::String)
new(name, age, occupation)
endendfunctionintroduce(p::Person)
println("Hi, my name is $(p.name) and I am a $(p.age)-year-old $(p.occupation).")
end
p1 =Person("Alice", 25, "Software Engineer")
introduce(p1)
As far as I understood, after correcting the code, the introduce function is just a normal function and not a custom method of struct Person.
The text was updated successfully, but these errors were encountered:
An example is given that it is possible to have a custom method inside a struct like this:
However, this code will not run and it should be changed to this:
As far as I understood, after correcting the code, the
introduce
function is just a normal function and not a custom method of structPerson
.The text was updated successfully, but these errors were encountered: