+ 2

Pointer manipulation

In the example given shouldn't it be obj->var instead of obj.var as we are calling function with &obj. Kindly clarify. Thanks in advance

27th Jul 2017, 3:49 AM
Lovish Arora
Lovish Arora - avatar
4 Answers
+ 1
if the function is defined like this: void func(MyClass & obj) then you call it like this: func(myobj) and inside func you refer to members like this: obj.var, obj.method() If func is defined like this: void func(MyClass * pobj) then you call it like this: func(&myobj) and inside it you refer to members like this: pobj->var, pobj->method()
27th Jul 2017, 8:29 AM
lion
lion - avatar
+ 8
We need the code sample, because lessons and codes don't link automatically when you post a thread.
27th Jul 2017, 4:47 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
ok I will attach code.
27th Jul 2017, 5:06 AM
Lovish Arora
Lovish Arora - avatar
+ 1
So my basic doubt comes to if we need to pass a function with address of an object, can we pass object name like we pass array name as base address? example function(obj) where obj is object of some class.
27th Jul 2017, 5:09 AM
Lovish Arora
Lovish Arora - avatar