Why should I use a pointer rather than the object itself?

后端 未结 22 1935
予麋鹿
予麋鹿 2020-11-21 23:26

I\'m coming from a Java background and have started working with objects in C++. But one thing that occurred to me is that people often use pointers to objects rather than t

22条回答
  •  春和景丽
    2020-11-22 00:03

    Let's say that you have class A that contain class B When you want to call some function of class B outside class A you will simply obtain a pointer to this class and you can do whatever you want and it will also change context of class B in your class A

    But be careful with dynamic object

提交回复
热议问题