Shortest and best way to “reinitialize”/clean a class instance

后端 未结 5 1824
感动是毒
感动是毒 2021-01-02 01:56

I will keep it short and just show you a code example:

class myClass
{
public:
  myClass();
  int a;
  int b;
  int c;
}

// In the myClass.cpp or whatever
m         


        
5条回答
  •  迷失自我
    2021-01-02 02:21

    myUsedInstance = myClass();
    

    C++11 is very efficient if you use this form; the move assignment operator will take care of manually cleaning each member.

提交回复
热议问题