Skip to content

Struct errors #195

Closed Locked Answered by crisadamo
survuvi asked this question in Q&A
May 18, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hey,
A couple of things happening here. Please, see the notes on the code below:

from String import String

@value
@register_passable("trivial")
struct Person:
    # 1) Need to specify its properties
    var name: StringRef
    var age: Int
    
    # 2) the constructor is __init__ otherwise to use who_is, you need to  make it static and return a new Person.
    #    You can also add the @value decorator to the struct and skip the constructor
    #fn __init__(inout self, name: StringRef, age: Int):
    #    self.name = name
    #    self.age = age
    
    # 3) your version needed a few changes and also needed the register_passable decorator
    @staticmethod
    fn who_is(name: StringRef, 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@survuvi
Comment options

Answer selected by survuvi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants