Coming from C#, this puzzles me. In Go, if I have
type Employee struct {
ID int
Salary int
}
then I can do
var tom Employee
tom.Salary = 100
so far so good. Then if I have a function
func employeeByID(id int) Employee {
// do something and return an employee
}
Then why does this not compile?
employeeByID(10).Salary = 100
Moreover, this seems to compile fine:
andrew := employeeByID(10)
andrew.Salary = 100
employeeByID(10).Salary = 100
to do? It would make sense if the function returned*Employee
instead.5 = 10
. Why would you want to assign a value to something that itself is not stored anywhere?