mercredi 7 novembre 2018

copy constructor for vector with objects

the default copy constructor of vector is defined as:

(4) copy constructor (and copying with allocator) Constructs a container with a copy of each of the elements in x, in the same order.

I got couple of questions about using this copy constructor. I got this vector:

 std::vector<OrderPair> orderList;

where

typedef std::pair<int, Dish> OrderPair;

and Dish is simple class (without pointers)

class Dish{
private:
    const int id;
    const std::string name;
    const int price;
    const DishType type;
};

Assume A is a vector as described above with some elements, which kind of copy I will get by doing:

std::vector<OrderPair> B=A;

in case the elements were created without new and in case they were created by new? what about the case the some of the fields of Dish were pointers?

Thank you.

Aucun commentaire:

Enregistrer un commentaire