Assertion message trick
03 Jun 2017Here is a simple trick to print a message when an assertion is violated. Assuming you have the following assertion:
assert(foo != nullptr);
You then just append the message you want to print to the check with a logical conjunction like this:
assert(foo != nullptr && "Usually due to not calling bar()");
Now, when this assertion fails the following message is printed:
Assertion `foo != nullptr && "Usually due to not calling bar()"' failed.