Link to home
Start Free TrialLog in
Avatar of Nusrat Nuriyev
Nusrat NuriyevFlag for Azerbaijan

asked on

4. Is it possible to pass objects as parameters and which options are available? What about returning as a result?

Is it possible to pass objects as parameters and which options are available? What about returning as a result?
SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nusrat Nuriyev

ASKER

>>> The object will be copied during the call, all changes are null and void.
1. Did you mean that the change which occures on the copied object absolutely does not affect to the original object?
1.1 The copied object lives its own life, and has its own life cycle?

>>> Thus, you should declare it as a 'const' parameter to help the compiler optimise.

2 .Do you mean this:

class MyClass {

  // ...
};


void foo(const MyClass obj)
{
 
    MyClass local_obj;
    // ...
    local_obj = obj;
    
}

Open in new window


3. So it's possible also to pass as pointer? Is there any difference in speed while passing by pointer and passing by reference? They basically affect to the original object. Should we prefer some way over other way?
4. is it impossible to return object by reference? Why?

>>> Note that there also a const references, which comes in handy when you don't want to copy large objects on the stack to make a function call.

5. Still do not get const stuff. Why we need const references?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jkr, answered like a boss :)