c++ - std::vector::clear() in constructor and destructor -
I encounter a number of times with the code where std :: vector :: clear () members of the square class std ::
- Constructor - Square member class std :: vector default The form is empty, so
- destructor - member class std :: vector of the square will be destroyed as part of standard destruction of the object. As part of vector destruction, all value objects will be destroyed (if they pile allocated points in memory, they should be "manually removed"), so again clear () Do not need to call.
Do I miss something?
By the sound of things, the people who wrote that code, what they once used to remember When it is clear that calling () a clear () call in a CTOR or DTOR will be in the middle of any other code. For example, a CTOR can read in some data, process it, and then read in more data. In such a situation, it may be possible to use a container to read the data, and instead of making it empty every time, instead of making a new container, make sure to create it every time.
Comments
Post a Comment