There are multiple answers/techniques to the below question:
I have a couple of answers but further discussion is required.
Defining a struct typeThe type keyword introduces a new type. It is followed by the name of the type ( Person ) and the keyword struct to indicate that we're defining a struct . The struct contains a list of fields inside the curly braces. Each field has a name and a type.
Default Value for Strings in Go The default or zero value for strings in the Go programming language is an empty string (i.e "").
A zero value struct is simply a struct variable where each key's value is set to their respective zero value. This article is part of the Structs in Go series. We can create a zero value struct using the var statement to initialize our struct variable.
Yes, there is a clear answer: C++ struct can have member functions.
One possible idea is to write separate constructor function
//Something is the structure we work with type Something struct { Text string DefaultText string } // NewSomething create new instance of Something func NewSomething(text string) Something { something := Something{} something.Text = text something.DefaultText = "default text" return something }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With