Skip to content

Files

Failed to load latest commit information.

Latest commit

 Cannot retrieve latest commit at this time.

History

History

incomparable_struct

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

不可比较的struct

定义个类型,是方法,并且长度为0,不占用任何空间。

将该类型放在struct中,让struct不具备比较能力,即==操作符在编译时都失效。

type Incomparable [0]func()
type Person struct {
        _    Incomparable
        Name string
}

报错:

./main.go:18:17: invalid operation: p1 == p2 (struct containing Incomparable cannot be compared)