What can I use instead of the arrow operator, `->`?


Question

What is the arrow operator (->) a synonym for?

1
101
1/7/2012 8:49:00 PM

Accepted Answer

The following two expressions are equivalent:

a->b

(*a).b

(subject to operator overloading, as Konrad mentions, but that's unusual).

130
10/21/2008 10:10:09 AM

a->b is generally a synonym for (*a).b. The parenthesises here are necessary because of the binding strength of the operators * and .: *a.b wouldn't work because . binds stronger and is executed first. This is thus equivalent to *(a.b).

Beware of overloading, though: Since both -> and * can be overloaded, their meaning can differ drastically.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon