C++ how to delete a structure?

前端 未结 11 1164
生来不讨喜
生来不讨喜 2020-12-31 03:42

Structure I created:

   struct VideoSample
  { 
      const unsigned char * buffer;
      int len;
  };

   VideoSample * newVideoSample = new VideoSample;
          


        
11条回答
  •  不知归路
    2020-12-31 04:09

    delete newVideoSample;
    

    But if the new and delete are in the same context, you're probably better off skipping them and just creating it on the stack instead:

    VideoSample newVideoSample = {buf, size};
    

    In that case, no cleanup is necessary.

提交回复
热议问题