in C++, what's the difference between an object and a pointer to an object?

前端 未结 7 523
温柔的废话
温柔的废话 2020-12-30 12:18

In java and objective-c, a variable representing an object is generally a pointer to that object. However, it seems that in C++, it\'s common to have non-pointer types hold

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 12:51

    In C++, a variable is the variable that it is representing. It is the actual object in memory, at the actual location.

    However, you can choose to make such a variable represent a pointer instead, in which case it'll say "Hey, I'm me, I am pointing over there! The object you want isn't here, it's THERE. Yes, there! Go on, get there!".

    Unless you're explicitly using C++'s "reference type", which I suspect you're not, then ALL arguments you pass are by value.

提交回复
热议问题