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

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

    I can't say that I am an experienced C++ programmer but I have recently learned how hard it is to pass and array of arrays as a function parameter. Try to avoid this at all cost :(

    If you know the size at compile its simple. Even if you know one of the dimensions at compile time. If you simply don't know... you might be looking at something like this

    m[i*dim2+j]
    

    Being i the iterator for the rows, dim2 the number of cols and j the iterator for the cols.

提交回复
热议问题