fork download
  1. type Person =
  2. ref object
  3. name: string
  4. age: int
  5.  
  6. proc new(T:typedesc[Person], name:string, age:int): Person =
  7. result.new()
  8. result.name = name
  9. result.age = age
  10.  
  11. proc greet(p:Person) =
  12. echo "Hello, I'm ", p.name, "."
  13. echo "I'm ", p.age, " years old."
  14.  
  15. proc main =
  16. let andrew = Person.new("Andrew", 28)
  17. let philip = Person.new("Philip", 26)
  18. andrew.greet()
  19. philip.greet()
  20.  
  21. main()
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.nim(2, 12) Error: expression expected, but found 'object'
stdout
Standard output is empty