Class destructor with c ++ pointer array

If I have a class with an array of pointers to another Vehicle class:

class List {
    public:
        //stuff goes here
    private:
        Vehicle ** vehicles;
}

If I write a class destructor now List, do a manual iteration over the array (I know how many elements are in the array) and deleteeach pointer to the vehicle, or C ++ will automatically call the destructors of all vehicles in the array?

(As in the case if the class has a separate line / ... or it will be a container of STL pointers of the vehicle)

EDIT: I forgot about delete [] vehicles, but if I did, would it also delete the memory used by all the machines in the array, or would it just delete the memory used by pointers?

+3
source share
4 answers

. ++ (STL), : , . scoped_ptr/shared_ptr , .

+6

Vehicle ( ), , .

+3

Vehicle:

Vehicle ** vehicles;

vehicles , Vehicle. Vehicle* vehicles[N].

( , )

! , ?

Boost::scoped_ptr Boost. , ++ 0x, std::unique_ptr

+2
source

You must manually sort through the vehicles and deleteeach of them.

0
source

Source: https://habr.com/ru/post/1786694/


All Articles