5.8 SOME SHORT QUESTIONs AND ANSWERS II

Q. Can we pass objects as parameter to functions?

A. Yes by all means.

Q. When methods work with objects why use objects as parameter?

A. A method is tied to one particular object. What if we want to compare two objects?

In that case, you need at least one object as a parameter.

Q. What are the basic ways of passing object as a parameter?

A. Just the same as other data types. Passing by value and passing by reference.

Q. What are the two ways in which object can be passed by reference?

A. First the traditional way, i.e. using pointer. Second using new reference operator (&). We recommend the second one.

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.