c++: when to use pointers?

后端 未结 14 1696
无人共我
无人共我 2020-12-12 22:48

After reading some tutorials I came to the conclusion that one should always use pointers for objects. But I have also seen a few exceptions while reading some QT tutorials

相关标签:
14条回答
  • 2020-12-12 23:50

    Pass by value with well behaved copyable objects is the way to go for a large amount of your code.

    If speed really matters, use pass by reference where you can, and finally use pointers.

    0 讨论(0)
  • 2020-12-12 23:50

    Use pointers when you don't want your object to be destroyed when the stack frame is emptied.

    Use references for passing parameters where possible.

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