0

Dot and arrow operator c++

Hey Guys, I have some problems to understand what the dot and arrow operator do in c++. I have to implement a singly linked list. But I don't know how to start and how to use the dot and arrow operator. Can you help me please?? :(

3rd Jul 2017, 8:28 PM
Elli
Elli - avatar
6 Respuestas
+ 2
When a pointer points to an object, you have two ways to access its member functions, like @Alex Stoica said: MyClass* object = MyClass(); object->doSomething(); (*object).doSomething(); The only place you use the arrow is for pointers to objects, or for the keyword 'this'.
3rd Jul 2017, 8:42 PM
Zeke Williams
Zeke Williams - avatar
+ 1
A pointer is a variable wich contain an adress. An adress is like '0x116f2c'. The adress of a variable is the place where it is in the memory. int a; // classic integer variable int *pa; // pointer on an integer /* '&a' is the adress of 'a' pa=&a; So here, 'pa' is a pointer, a variable. Its value is the adress of the variable 'a'. cout<<pa; will output an adress something like this : 0x3h56g2. You can access to the value of 'a' with 'pa' : *pa==a Conclusion : pa==&a and *pa==a If you don't understand or if you want à code to have an exemple, ask !
3rd Jul 2017, 8:44 PM
Jojo
+ 1
Hey Thank you for your help!!
4th Jul 2017, 5:25 PM
Elli
Elli - avatar
+ 1
It doesn't really answer, to your first question but if you learnt something in my answer, you couldn't understand '->' operator 😊
4th Jul 2017, 6:34 PM
Jojo
0
You should learn about pointers. a->b and (*a).b are equivalent
3rd Jul 2017, 8:29 PM
Alex Stoica
0
I try it, but it's a big problem for me to understand it :/
3rd Jul 2017, 8:32 PM
Elli
Elli - avatar