Some people think that if an object occupies a tiny bit of memory, say 4 bytes, returning such an object by value is as efficient as returning int by value. This isn't the case. Agreed, lightweight objects do not contain data members and therefore don't occupy much memory. However, their initialization can be quite complex, for example, when the object has virtual functions or base classes. Therefore, don't rely only on sizeof(obj) to decide if the object can be passed by value efficiently. If its initialization isn't trivial, you should return and pass such objects by reference, too.
Take advantage of special member promotions, everyday discounts, quick access to saved content, and more! Join Today.