-11

I've run across this pointer construction and I'm not familiar with it. Can someone explain please.

void Test_GPS::begin(uint16_t baud)
{
    gpspointer->begin(baud);
}

What does the -> do? And it seems recursive.

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100

1 Answers1

2

You should really get a C/C++ Book and learn your language, before you start programming.

-> is the dereferencing operator for Pointers. When you have a pointer gpspointer the expression (*gpspointer) returns the object gpspointer points to. (*gpspointer).begin(baud) is the same as gpspointer->begin(baud). It just increases readability.

Your code will recurse only if gpspointer=this.

ikrabbe
  • 1,909
  • 12
  • 25
  • Thank-you ikrabbe. Makes sense now. I hadn't seen that representation before. My K&R book doesn't mention it. – Trillian86 Jun 23 '15 at 12:04
  • 3
    K&R is about ANSI C, not C++ and I doubt that K&R does not mention the `->` operator. Hmm It's about 25 years ago I read my K&R, so maybe I'm wrong on this. – ikrabbe Jun 23 '15 at 12:05
  • @Trillian86 The index says it's on pages 131 and 201 in the 2nd edition. – molbdnilo Jun 23 '15 at 12:34