I have the following class:
class Student { private: std::string firstName; std::string lastName; public: Student():firstName(""), lastName("") { } Student(const std::string &first, const std::string &last) :firstName(first), lastName(last) { } Student(const Student &student) :firstName(student.firstName), lastName(student.lastName) { } Student(Student &&student) { firstName=std::move(student.firstName); lastName=std::move(student.lastName); }
I use it as follows:
std::vector<std::shared_ptr<Student>> students; std::shared_ptr<Student> stud1 = std::make_shared<Student>("fn1","ln1"); students.push_back(stud1); Student stud2("fn2","ln2"); students.push_back(std::make_shared<Student>(std::move(stud2)));
From what I read, the move constructor is automatically generated by the compiler. Right now, when I enter this line students.push_back(std::make_shared<Student>(std::move(stud2))); I get to the move constructor, which is good.
If I comment out the move constructor when entering this line, I will get to the copy constructor. I do not understand why this is happening.
source share