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

前端 未结 16 2140
刺人心
刺人心 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:19

    Here is another one i caught some day:

    char int2hex(int x) {
         return "-0123456789abcdef"[(x >= 0 && x < 16) ? (x + 1) : 0];
    }
    

    it's just indexing the char array instead of doing a switch. If it's outside the range, it returns '-'.

提交回复
热议问题