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

后端 未结 5 1819
感动是毒
感动是毒 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:19

    You may want to consider using placement new. This will allow you to use the same memory but call the constructor again.

    Don't forget to call the destructor before using placement new, however.

提交回复
热议问题