复制对象向量的构造函数

时间:2018-11-07 23:29:34

标签: c++ c++11 vector

vector的默认副本构造函数定义为:

  

(4)复制构造函数(并使用分配器复制)       用相同的顺序构造一个容器,其中包含x中每个元素的副本。

关于使用此副本构造函数,我有几个问题。 我得到了这个向量:

 std::vector<OrderPair> orderList;

其中

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

并且Dish是简单的类(没有指针)

enum DishType{
    VEG, SPC, BVG, ALC
};

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

假设A是如上所述的向量,其中包含一些元素, 我将获得哪种副本:

std::vector<OrderPair> B=A;

是在没有新元素的情况下创建元素还是在新元素的情况下创建元素? 那么Dish的某些字段是指针呢?

谢谢。

0 个答案:

没有答案
相关问题