dot notation vs pointer
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/oa 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.
上一篇: 我应该在什么时候分配堆? (C ++)
下一篇: 点符号与指针