Please help with -> symbol !

I really need a good understanding with -> .
I went through numerous times through textbooks, but I just do not understand how to use it! Would someone please explain easily with examples? Thank you!
closed account (9wqjE3v7)
'->' is an operator, it allows you to access values pointed by a member of an instance. For instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

class vertex_data {
public:
float x;
float y;
};

int main() {

vertex_data *  a; //create a pointer to an instance of the class vertex_data.
vertex_data b;

a = &b;

a->x = 10 // member x of object pointed by a is initialised with the value 10.
(*a).x = 10; // exact same instruction, just not as great syntactic sugar and can get a little confusing.

return 0;
}
Last edited on
Thanks very much!
Topic archived. No new replies allowed.