What could go wrong if you do not pass objects by reference to a function

I am trying to teach some students that in the following case, you must follow the link, otherwise the objects will be copied.

note: they do not yet know about copy constructors, so if possible, I would not want to mention them in this example.

int sumOfSizes(CObject const & a, CObject const & b)
{
    return a.getSize() + b.getSize();
}

Can someone help me with a real example where the amount is not as expected?

+3
source share
1 answer

@Space_C0wb0y , - "" - CObject - "" (, CObject ( ) ). , , .

, CObject.

+6

All Articles