question about function formating

I have a question about function calls and their format. someone in another thread had this written as a function and i was hoping someone could clear it up for me. I dont know if im having a major brain fart or what.

IWatch->GetPosition().x

the way i read it is IWatch is a class pointer to the member function GetPosition that takes 0 arguments. What is .x doing there? it looks like a member access operator for a class or a structure but ive never seen it used on the tail of a function before.

this is the thread the code is from
http://www.cplusplus.com/forum/beginner/45554/

if someone could straighten this out for me it would be appreciated.
Last edited on
Consider this:
1
2
3
4
5
6
7
8
9
10
11
12
13
struct Pos
{
  int x, y;
};

class Watcher
{
  Pos GetPosition()
  {
    Pos somrandomposition = {13, 37};
    return(somerandomposition);
  }
} *IWatch;


Now, look at your code again - since GetPosition returns a Position, you can either store it in another Pos object first and then get the x, or just get the x right off the bat. Obviously the second option is easier :)
Last edited on
ok ive never seen that before in any of the c++ examples ive read. I made my own example based off of your code and it worked. thats really cool and a neat shortcut. thanks for showing it to me. I never knew you could do that. really interesting.
Topic archived. No new replies allowed.