C++ function parameters: use a reference or a pointer (and then dereference)?

后端 未结 11 2410
臣服心动
臣服心动 2021-02-05 10:49

I was given some code in which some of the parameters are pointers, and then the pointers are dereferenced to provide values. I was concerned that the pointer dereferencing wou

11条回答
  •  没有蜡笔的小新
    2021-02-05 11:13

    If you need to do things like bellow to remember that "a" is going to be changed on the function. What will stop you from inverting parameters that have same type or making some nasty error, when you have to call some function you must keep the prototype on your memory, or use some IDE that show it on a tooltip. There no excuse for that, I don't like references because I cant know if the function will change it, is not an valid argument.

    MyFunc2(/*&*/a, /*&*/b)
    

提交回复
热议问题