Hi, I have a requirement to write a setter which only set the base class fields
for a inherited class, here is my current code.
type
Base* = object of RootObj
name*: string
age*: uint
job*: string
BaseExt = object of Base
skills: seq[string]
proc `setBase=`(o: var BaseExt, b: Base) =
for fe, ve in o.fieldPairs:
for fb, vb in b.fieldPairs:
when fe == fb:
ve = vb
var b = Base(name: "Biden", age: 79, job: "N/A")
var body = BaseExt(skills: @["sleep", "hug"])
body.setBase = b
Run
is my implementation correct?