How to Dereference object? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to Dereference object?

normally, int x = 5; int *p = &x; p = address of x *p = x = 5 in oop : SomeClass obj; obj.func(); SomeClass *p = &obj; so now we have to use, p->func(); but if I try, *p.func(); [*p should be Dereferenced and should work as obj] this gives an error. why does this happen

10th May 2018, 11:13 AM
Munna Aziz Rahaman
Munna Aziz Rahaman - avatar
2 Answers
+ 3
This may be because the member access operator is evaluated before the dereference operator. Try (*p).func()
10th May 2018, 11:17 AM
Vlad Serbu
Vlad Serbu - avatar
+ 1
Thanks! It worked.
10th May 2018, 11:19 AM
Munna Aziz Rahaman
Munna Aziz Rahaman - avatar