Using a setter for a struct type does not work as anticipated

后端 未结 2 1683
故里飘歌
故里飘歌 2020-11-29 13:14

Using a setter function for a struct, but not working as anticipated:

package main

import \"fmt\"

type T struct          


        
2条回答
  •  借酒劲吻你
    2020-11-29 13:40

    That's the difference between call by value and call by reference. If you are from C++ background , then you would know that it's the same in C++ also. And if you are from java background, then remember all object references are just pointers to the objects really..(meaning to say, when we do Node node = new Node();.. the node is holding the address of the new node object created). Therefore any method on the object(node) is actually called by reference(because node itself is a pointer).. so it reduces back to the same example as above.

提交回复
热议问题