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

前端 未结 7 520
温柔的废话
温柔的废话 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:42

    You have that right.

    Indeed, that's how it works. A pointer stores the memory address of a variable.

    When you pass a pointer (to an object) for a function as a parameter, it means that function will have access to that object through it's memory address instead of a new object being created on the stack.

    Check this thread for more info on pointers.

提交回复
热议问题