Relative Content

Tag Archive for idioms

clone() only partially doable; how to react?

Suppose we have a class-hierarchy whose base class B requires a clone() method to be defined in its derivations. Whilst this works perfectly for most of them there is this one derivation X that holds an optional reference to a resource/object that can only be referenced from one instance of X. Whilst the rest of X can be cloned without problems this reference would have to be set to null/nil/nullptr.

clone() only partially doable; how to react?

Suppose we have a class-hierarchy whose base class B requires a clone() method to be defined in its derivations. Whilst this works perfectly for most of them there is this one derivation X that holds an optional reference to a resource/object that can only be referenced from one instance of X. Whilst the rest of X can be cloned without problems this reference would have to be set to null/nil/nullptr.

Is checking return values always required? [duplicate]

This question already has answers here: How should I handle exception that *should* never be thrown? [duplicate] (5 answers) Closed 9 years ago. We know that checking return values prevent our software from unexpected states. (You can see CWE definition.) But, we are sometimes sure about the return value. For example: bool calculateSquareRootReturnFalseIfInputIsNegative(float input, float& […]