swift - Error Cannot invoke initilizer of type 'Box<T>' -
why not allowed?
class box<t>{ let value: t init(_ value:t){ self.value = value } func map<u>( f: t -> u)->box<u>{ return box(f(self.value)) } }
error @ return box(f(self.value))
:
error : cannot invoke initilizer of type 'box<t>' argument list of type '(u)'
you have specify type box
object you're returning:
class box<t> { let value: t init(_ value:t){ self.value = value } func map<u>(f: (t) -> (u)) -> box<u> { return box<u>(f(self.value)) } }
within context of box<t>
class implementation, references box
assumed box<t>
unless explicitly specify type (as did box<u>
, in return
statement, above).
Comments
Post a Comment