C++ completely erase (or reset) all values of a struct?

前端 未结 3 1814
长情又很酷
长情又很酷 2020-12-25 14:37

So, I was just wondering how could we completely erase or reset a structure so it could be reused?

I just typed this up, here you go:

typedef struct          


        
3条回答
  •  时光取名叫无心
    2020-12-25 15:13

    You can just assign a constructed temporary to it:

    Part my_struct;
    
    my_struct = Part(); // reset
    

    C++11:

    my_struct = {}; // reset
    

提交回复
热议问题