I have a class (struct) like this:
type Question struct{
Question string
answerOne string
answerTwo string
answerCorrect string
}
And I initialize it like this:
q1:=Question{
Question:"What?",
answerOne:"A",
answerTwo:"B",
answerCorrect: ? //I want this have similar value as `answerOne`
}
While initilizing I want one of my values have similar value as another one. Is there any way to do that?
You cannot by using only literals, but you could define a function.
func NewQuestion() *Question {
q := &Question{
Question: "What?",
answerOne: "A",
answerTwo: "B",
}
q.answerCorrect = q.answerOne
return q
}
// ...
q1 := NewQuestion()