"Go Learning Notes" 10, struct struct

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

struct struct

    • The struct in Go is very similar to the struct in C, and go has no class
    • define structure with type struct{}, name follows visibility rules
    • Supports pointer-type members pointing to themselves
    • Supports anonymous structures that can be used as members or define member variables
    • Anonymous structures can also be used for map values
    • Structure can be initialized with literal values
    • Allows you to read and write struct members directly through pointers
    • Members of the same type can perform direct copy assignment
    • The = = and! = Comparison operators are supported, but not > or <
    • Support for anonymous fields, essentially a field defined by a type name
    • Embedded structure as anonymous field looks like inheritance, but not inherited
    • You can use the anonymous field pointer
1234567891011121314151617181920212223242526272829
typeHumanstruct{Sexint}//Use combination//Similar inheritancetypeTeacherstruct{HumannamestringAgeint}typeStudentstruct{HumannamestringAgeint} func main() {A: = Teacher{name:"Joe", Age: +, Human:human{sex:0}}a: = Student{name:"Joe", Age: -, Human:human{sex:1}}a.name ="Joe2"A.age = -A.sex = -}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.