Possible Duplicates:
C++: ptr->hello(); /* VERSUS */ (*ptr).hello();
Why does C have a distinction between -> and . ?
I know the difference between the member operator (.) and the member by pointer operator (->).
Why did the C designers create a different operator for this access? Why can’t the compiler figure it out on its own?
If you always used a . does any case exist where it is ambiguous whether you mean a member or a member by pointer?
edit: I’m not looking for the “(*a).b” syntax. I asking why didn’t the designers allow you to use “a.b” instead of “a->b”?
When you have a language that is, at its core, intended to be a “portable assembler” you don’t try to hide implementation details from the user. Of course the compiler can figure out that in the expression
a.btheain question is a pointer. Can you? Reliably? All the time? In hairy, complicated code? And can you not envision a circumstance where not being able to quickly note thatais a pointer could be a problem?Stop thinking in terms of “hard to write” and start thinking in terms of “easy to read”. (Yeah, I know. This goes against the whole C programmer mythos!) You’ll be reading code a couple of orders of magnitude more often than you’ll be writing it.