quick question.

What does the operator "->" do?

Also if it's no trouble could I have a syntax example.
It is generally used to give a pointer like syntax to an object. As for an example, it's just like operator =, where the right hand side is the argument to the function.
OK thanks.
Normally you access objects methods like this (saying that dog is my object here):
dog.bark();

well when I have a pointer to my dog:
Canine *sirus = &dog
I cannot just go
sirus.bark();

I now need to dereference my pointer (with *), but I also can't just go *sirus.bark() because we run into an operator precedence problem. That's right, both '*' and '.' are operators and unfortunately (for our needs) the '.' operator goes first, then '*'.

So my program is trying to dereference at this point some object named sirus with a method bark() and dereference any pointer that comes back. The way to avoid precedence is to use () so then our syntax is now:
(*sirus).bark();

Which when your code becomes long (1 million lines of code!) it can become quiet messy. The -> operator handles this precedence operator problem altogether. Now you no longer need neither either of the previous and get a nice syntax like:
sirus->bark();
Topic archived. No new replies allowed.