C++: Reasons for passing objects by value

前端 未结 8 1284
清酒与你
清酒与你 2021-01-06 12:37

In Java, all variables containing proper objects are actually references (i.e. pointers). Therefore, method calls with these objects as arguments are always \"by reference\"

相关标签:
8条回答
  • 2021-01-06 12:52

    If you pass objects to a function by value, that function is free to use those objects as "working" variables without affecting the caller.

    0 讨论(0)
  • 2021-01-06 13:00

    It's helpfull to avoid side-effects. If you program need such side-effect use call by reference.

    0 讨论(0)
提交回复
热议问题