#Ziglings Question 65: `'fetchTheMostBeautifulType' is not a member function`

1 messages · Page 1 of 1 (latest)

topaz skiff
#

Hey there, I am working through ziglings and have been held up by question 65.

I am confused by the error about fetchTheMostBeautifulType not being a member function when, to me, it's defined on struct Narcissus.

I am using 0.11.0-dev.3949+27a66191c

Here is the original code:

https://github.com/ratfactor/ziglings/blob/main/exercises/065_builtins2.zig

My answer is attached

GitHub

Learn the Zig programming language by fixing tiny broken programs. - ziglings/exercises/065_builtins2.zig at main · ratfactor/ziglings

willow stump
#
// Oh dear, we seem to have done something wrong when calling
// this function. We called it as a method, which would work
// if it had a self parameter. But it doesn't. (See above.)

to call a function on a struct instance, it needs to take the instance as the first parameter (as a value or pointer to the struct type), which is conventionally called self. since fetchTheMostBeautifulType() doesn't have such a parameter, you need to call it on the Narcissus struct itself, not on a particular instance like narcissus.

topaz skiff
#

That makes perfect sense 💡 Thank you @willow stump

I also don't understand what is going on here, incredible I could pretty confidently get this far

willow stump
#

fields[0].name is the name of the struct field... so in that example fields[xyz].name will be "me", "myself", and "echo"

#

and since those are strings they have type []const u8

#

the actual type of those fields is in .type

#

so e.g. fields[0].type == void

#

wait no it's not void it's *Narcissus but you know

topaz skiff
#

I see, thank you again friend

green temple
#

I was looking for this ^^