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

前端 未结 16 1992
刺人心
刺人心 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条回答
  •  萌比男神i
    2021-01-29 20:13

    Do not fall into the trap of using std::noncopyable unless needed. Yes, it is useful at a lot of places, and should be used there.

    The trap is that one starts writing clone() function along with making it noncopyable, which implements the same functionality. Instead, you can also use explicit (link) for the copy constructor instead to prevent accidental copying (and make assignment private, or delete the function in C++0x). clone() is needed for inherited base classes though.

提交回复
热议问题