Originally Posted by
Zlatko
Generally, as Elysia and I demonstrated, pass around and return references instead of making copies of objects. Any function declaration should use the reference modifier ('&') for any objects unless there is a reason for making copies. To ensure that your coding doesn't accidentally modify the object being referred to, you can specify const for the parameter.
For example
void foo(const string& s);
The same goes for return values. You can specify
const string& getString();
Then getString can only be assigned to a const reference.
const string myString& = myObject.getString()
When storing objects in containers, you can allocate the objects on the heap (using new), and store the pointers. Otherwise the object is copied multiple times before getting into the container. This becomes more important as objects get bigger.
Objects can become deceptively large when using inheritance. The class you develop might be small, but it might inherit from a huge one that you have no idea about.
The other place to optimize is your algorithms. That's a whole other topic.