C++ how to delete a structure?

前端 未结 11 1158
生来不讨喜
生来不讨喜 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:16

    Use delete

    VideoSample * newVideoSample = new VideoSample;
    //.. stuffs
    
    delete newVideoSample;
    

    There is also an overload i.e delete[]

    VideoSample * newVideoSample = new VideoSample[n];
    //.. stuffs
    
    delete [] newVideoSample;
    

    In Modern C++ it is always recommended to use smart pointers. You may want to use boost::shared_ptr from the boost library.

提交回复
热议问题