草庐IT

capability_type

全部标签

arrays - 无法对二维数组的列进行 slice "cannot use Sudoku[0:9][0] (type [9]int) as type []int in assignment"

我正在使用9x9二维数组的slice制作一个简单的数独游戏。我仍然刚开始使用Golang并且有一些C++经验。我不断收到错误消息“无法将数独[0:9][0](类型[9]int)用作赋值中的类型[]int”。varrow1[]int=数独[0][0:9]该行正确地获取了二维数组第一行的值并将它们放入row1slice中,但是使用varcol1[]int=Sudoku[0:9][0]会导致上面的错误消息。我能做什么?提前致谢!例如,packagemainimport"fmt"funcmain(){varSudoku[9][9]intfmt.Println(Sudoku)varrow1[]i

go - 不能在go lang中将type []字符串用作类型字符串

请帮助我如何解决此问题,我收到此错误不能在附加中将Title1(类型[]c)用作类型[]string。一旦我在这行上追加文章=附加(文章,标题1)谢谢typeastruct{Title[]bTitle1[]cArticle[][]string}typebstruct{DDstringFFint}typecstruct{CCstringEEstring}typedstruct{DDstring}funcmain(){xx:=b{}Title:=[]b{}yy:=c{}Title1:=[]c{}Article:=[][]string{}fori:=0;i提前致谢

go - .(type) 在 go 中如何工作

functest(valueinterface{}){ifres,ok:=value.(string);ok{fmt.Println(res)}}如何去确认值的类型?我没有发现struct中有任何东西可以表示类型。请帮忙。 最佳答案 Underthecovers,interfacesareimplementedastwoelements,atypeandavalue.Thevalue,calledtheinterface'sdynamicvalue,isanarbitraryconcretevalueandthetypeisthat

go - "Cannot use myType as type interface{}"?我以为在 Go 中所有类型都算作 interface{}?

这个问题在这里已经有了答案:Convert[]stringto[]interface{}[duplicate](3个答案)Convertingsliceofstructstosliceofemptyinterface[duplicate](1个回答)Whycan'tIsubstituteasliceofonetypeforanotherinGo?(3个答案)Whycan'tIpassa`func()[]int`as`func()[]interface{}`ingo?(2个答案)Whyaslice[]structdoesn'tbehavesameas[]builtin?(3个答案)关闭4

go - Type a type后,不能再混用

config.Config有一个方法funcString(string)string我想将这些方法混合到我的类型Config1.什么时候可以//typeConfigstructtypeConfigstruct{//astructhasmanymethodsconfig.ConfigPathstring}//newandcallstringmethodvaraConfig=&Config{}a.String("test")什么时候不行//typeConfigstructtype(Configureconfig.ConfigConfigstruct{ConfigurePathstring}

go - 不能使用 args (type []string) 作为 type []interface {}

这个问题在这里已经有了答案:Typeconvertingslicesofinterfaces(9个回答)关闭3年前。我的golangsqlite插入函数。我正在使用这个包"github.com/mattn/go-sqlite3"funcInsert(args...string)(errerror){db,err:=sql.Open("sqlite3","sqlite.db")iferr!=nil{return}q,err:=db.Prepare(args[0])iferr!=nil{return}_,err=q.Exec(args[1:]...)return}main(){err:=I

go - 在 golang 中,如何将 interface{} 类型断言为 reflect.Type 指定的类型?

例如,我有一个名为a的interface{},还有一个名为elemTypereflect.Type/。现在,我想给elemType键入asserta,但是a.(elemType)无法编译成功。如何解决?对不起我的困惑表达。我的意思是我从一个函数中得到一个类型,我想为这个类型断言一个接口(interface){},但是这个类型存储在一个reflect.Type变量中。我想做的类似于下面的代码:varainterface{}//dosomethingfuncgetType()reflect.Type{varretreflect.Type//dosomethingreturnret}targ

go - 传播时 "Cannot use variable of type []struct as []interface"

这个问题在这里已经有了答案:sliceofstruct!=sliceofinterfaceitimplements?(6个答案)关闭8个月前。原型(prototype)函数functest(i...interface{}){//Codehere}预期用途typefoostruct{//Fields}foos:=[]foo{//foo1,foo2...}test(foos...)//ERRORtest(foos[1],foos[2],...)//OK错误cannotusefoos(variableoftype[]foos)as[]interface{}valueinargumenttot

go - type <Name> <dataType> 和 type <Name> = <dataType> 有什么区别

我是Golang的新手。抱歉,我仍然对以下两者之间的区别感到困惑:type和type=这是一个例子:packagemainimport"fmt"funcmain(){var(strWordWordstrTextText)strWord="gopher"strText="golang"fmt.Printf("strWord=%s,TypeofValue=%T\n",strWord,strWord)fmt.Printf("strText=%s,TypeofValue=%T\n",strText,strText)}typeWordstringtypeText=string输出strWord=

go - *[]Type 和 []*Type 在 go 中有什么区别

假设我们有一个名为Person的结构,它由一个名为People的结构持有。typePerson{Namestringageint}typePeople{CitystringList[]*Person//checkthisout}typePeople2{CitystringList*[]Person//What'sthedifference?}[]*Person和*[]Person到底是什么意思?如何获取这些slice的元素值?我比较熟悉C,所以如果你能用C解释一下,我将不胜感激 最佳答案 []*Type是指向Type的指针片段。*[