-2

Is it different from foo.bar calling a function from a specific instance? I've seen it around on tutorials but it's never explained and it's too general a term to show up on google.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
fRIITable
  • 29
  • 1
  • 3

3 Answers3

1

Operator operator-> can only be used on a pointer type (in that case foo->bar is equivalent to (*ptr).bar) or a type that overloads operator-> (in that case the semantic depends on the overload itself).

An example with a pointer type might be:

struct some {
    int x;
};

some a{10};
some* a_ptr = &x;

a.x = 10;
a_ptr->x = 10;

An example for an overloaded type could be:

std::unique_ptr<some> a_ptr = std::make_unique<some>(10);
a_ptr->x = 10;
Shoe
  • 74,840
  • 36
  • 166
  • 272
0

foo->bar is short for (*foo).bar. (Unless foo is of some class type for which -> does something else).

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
0

foo->bar is used when foo is pointing to a certain data type foo.bar is used when foo is an object of a class

guest1234
  • 5
  • 2