What are some C++ related idioms, misconceptions, and gotchas that you've learnt from experience?

前端 未结 16 1805
刺人心
刺人心 2021-01-29 19:48

What are some C++ related idioms, misconceptions, and gotchas that you\'ve learnt from experience?

An example:

class A
{
  public: 
  char s[1024];
  cha         


        
16条回答
  •  鱼传尺愫
    2021-01-29 20:20

    I've liked this since the time i've discovered it in some code:

    assert(condition || !"Something has gone wrong!");
    

    or if you don't have a condition at hand, you can just do

    assert(!"Something has gone wrong!");
    

    The following is attributed to @Josh (see comments). It uses the comma operator instead:

    assert(("Something has gone wrong!", condition)); 
    

提交回复
热议问题