Possible Duplicate:
Why does C have a distinction between -> and . ?
What is the real reason for a programmer to have to differentiate between .
and ->
when accessing a member of an object?
void foo( Point &p ) {
p.x ;
p->y; // syntax error
}
void foo( Point *p ) {
p.x ; // syntax error
p->y;
}
I mean, one way or another, they both refer to an object, p.
Why do I have to bother checking every time what p is ? Can't the compiler understand ?
Why haven't they allowed it to accept
.
syntax for both? That would be fine for stack objects too.
And if it is due to C-tradition,
- Why don't they allow both
.
and->
accessors?
For more than 15 years, I have always humbly considered the compiler errors as being my fault !