Pointer manipulation | Sololearn: Learn to code for FREE!

+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

7/27/2017 3:49:24 AM

Lovish Arora

4 Answers

New Answer

+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()

+8

We need the code sample, because lessons and codes don't link automatically when you post a thread.

+1

ok I will attach code.

+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.