Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the advantage of passing a object by reference?

0
Posted

What is the advantage of passing a object by reference?

0

memory consumption is less ( copy constructor is not fired) b) avoid slicing problem ( function are called based on the context of the object and not based on the type of the object) Ex: Class A; Class B:public A ; IndependentFun( A a) { a.Fun(); } void main() { B b; IndependentFun(b); } output : A::Fun() will be called ( A a = b) -> type of object is used if it was reference like IndependentFun( A& a) now the output will be B::Fun().

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123