开发者

C++ Classes - dot notation vs pointer [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

What is the difference between the dot (.) operator and -> in C++?

What's the difference between using dot notation and the pointer way?

Instantiating an object with or without a pointer.

Instantiate w/开发者_运维知识库o a pointer = then use dot notation

Instantiate w/ a pointer = then use ->

What are the differences between both? When and why should one be used over the other?


If I understand your question: in C++, a->b is just shorthand for (*a).b -- they're exactly the same (Edit: unless you've overloaded them to behave differently!), it's just that the first is easier to type. :)

If you're referring to using string a; versus string* a = new string(), that's a different topic -- look up stack-based and heap-based allocation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜