why "." and "->" operators ?

G

Guest

I used to remember why c++ needed both.

For example

class A{

f();

};



A* aa;



You could do either "aa->f()" or "(*aa).f()". So why does C++ need both
operators.



Raj
 
D

David Harmon

On Wed, 23 Jun 2004 15:48:09 GMT in comp.lang.c++,
You could do either "aa->f()" or "(*aa).f()". So why does C++ need both
operators.

I guess this is a question for you to ask Dennis Ritchie in
alt.folklore.computers
It certainly goes back to the early days of C.

In C, aa->f() is strictly a convenient shorthand way to write (*aa).f().

in C++, if aa is an instance of a class that overloads operator*()
and/or operator->(), then they may not be strictly identical. It would
be a bad idea to make those operators behave in some bizarre unexpected
way, but you might easily have some reason to add some special behavior
to them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top