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);
}
// ... getters and setters
};
I use it like this:
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 have read, the move constructor in automatically generated by the compiler.
Right now, when I step into this line students.push_back(std::make_shared<Student>(std::move(stud2)));
I reach the move constructor, which is ok.
If I comment out the move constructor when I step into that line I reach the copy constructor. I don't understand why this is happening.