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?? :(
6 odpowiedzi
+ 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'.
+ 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 !
+ 1
Hey Thank you for your help!!
+ 1
It doesn't really answer, to your first question but if you learnt something in my answer, you couldn't understand '->' operator 😊
0
You should learn about pointers.
a->b and (*a).b are equivalent
0
I try it, but it's a big problem for me to understand it :/