我的情况下,我不明白这个解释。可能是这样,因为我想使用界面
multiple-value NewObject() in single-value context在以下情况下出现错误
type Facade interface {
GetOne() int
}
type ObjectOne struct{
one int
}
func NewObject()(Facade, error){
o := &ObjectOne{}
return o , errors.New("Some funny error")
}
func(o * ObjectOne)GetOne()int{
return 1
}
func SomeWhereInCode(){
newFacade , err := Facade(NewObject())
// And here. I get error probbably because Facade constructor return one arguments (interface) and NewObject() return two. How should be ?
}
我也error尝试过作为指针传递,ObjectOne但仍然得到错误编译器
type Facade interface {
GetOne() int
}
type ObjectOne struct{
one int
}
func NewObject(facadeError* error)(Facade, error){
o := &ObjectOne{}
*facadeError = errors.New("Some funny error")
return o , *facadeError
}
func(o * ObjectOne)GetOne()int{
return 1
}
func SomeWhereInCode(){
var facadeError = error()
newFacade , err := Facade(NewObject(&facadeError))
}
缥缈止盈
呼啦一阵风
相关分类