c++: when to use pointers?

后端 未结 14 1755
无人共我
无人共我 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:39

    Main reasons for using pointers:

    1. control object lifetime;
    2. can't use references (e.g. you want to store something non-copyable in vector);
    3. you should pass pointer to some third party function;
    4. maybe some optimization reasons, but I'm not sure.

提交回复
热议问题