Sometimes if you try to do multiple things in one statement, you should think carefully about abnormal behavior especially exceptions. For example:
1 | processWidget(std::tr1::shared_ptr<Widget>(new Widget), priority()); |
With this statement, if compile choose to do things in following order:
- Execute “new Widget”.
- Call
priorigy(). - Call the
std::tr1::shared_ptrconstructor.
In addition, if the call to priority yields an exception, you are running into resource leak. Because the pointer returned from “new Widget” will be lost before it’s put intoshared_ptr.
So what’s the suggestion? Don’t combine too many calls into one statement, especially dangerous ones like new objects.