Using the initializer lists is encouraged in general. Now let’s say I have the following code (trivial example just to make the question clearer):
class foo
{
public:
foo(ptr1* a, ptr2* b) : m_a(a), m_b(b), m_val(a->val) {}
/* code and members here */
};
I would like to check that a is not NULL before it tries to dereference it to get val. Is there any way I can perform a sanity check there?
Use the ternary operator:
The above sample outputs
-1.