I'm trying to use inheritance in Go, and although inheritance isn't 'technically' supported (as far as I know), you can get similar functionality by using anonymous fields.
Here's how I'm defining 'inheritance' for across two structs:
//Parent struct:
type FSEntity struct {
guid GUIDNumber
}
//Child struct:
type DataBlock struct {
FSEntity
data []byte
}
I now have a function defined as following, which is supposed to accept an instance of the parent struct FSEntity
:
Put(entity FSEntity) {....}
But when I try passing an instance of DataBlock
(which through inheritance is also FSEntity
) into the Put
function above like so:
guidNumber := GUIDNumber(1234)
value := []byte("sample string")
dataBLock := DataBlock{FSEntity{guidNumber}, value}
Put(dataBLock)
On the last line above, I get this error:
cannot use dataBLock (type DataBlock) as type FSEntity in argument to Put
How do I resolve this ?