dimanche 31 décembre 2017

Implicitly defined vs Explicitly declared constructor

What is the difference of an implicitly defined and explicitly declared default/copy constructors? Example:

    struct road{
     std::string id;
     std::string type;
     std::vector<int> nodes;
     road() = default;
     road(const & road c_road) = default;
     road(road && m_road);
   };

and

struct road{
 std::string id;
 std::string type;
 std::vector<int> nodes;
 road(road && m_road);
};

also what is the difference from defining my own constructors like

road::road(){}

road::road(const road & c_road):id(c_road.id)), type(c_road.type)),
  nodes(c_road.nodes){}

My question is, do I need to explicitly declare a default contructor (= default; version) or should I just rely on the implicit one? Is any version faster or safer in any way? Is any version "wrong"?

Aucun commentaire:

Enregistrer un commentaire