Complete the code to define a method with a value receiver.
type Counter struct {
count int
}
func (c Counter) Increment() {
c.count++
}
The method receiver must be a variable name, here c is the value receiver variable.
Complete the code to call the Increment method on a value receiver.
c := Counter{count: 0}
c.[1]()
fmt.Println(c.count)
The method name is Increment with uppercase I to export it.
Fix the error in the method receiver declaration.
func (c *Counter) Increment() {
c.count++
}
The receiver variable must be a name like c, not a type or pointer dereference.
Fill both blanks to define a method with a value receiver and print the count.
func (c Counter) PrintCount() {
fmt.Println(c.count)
}
The receiver variable is c and the type is Counter for a value receiver.
Fill all three blanks to create a value receiver method that increments count and prints it.
func (c Counter) IncrementAndPrint() {
c.count++
fmt.Println(c.count)
}
The receiver variable is c, the type is Counter, and the field accessed is count.
