mercredi 28 octobre 2020

Is std::move overkill in this situation?

Hi StackOverflow community, I was wondering if using the std::move in this regard is overkill or computationally more expensive than simply copying it? I would really like to know.

class Student
{
    private: 
        std::string _studentName;
        int _studentGrade;
    public:
        Student() : _studentName("No Name"), _studentGrade(0) {}

        std::string Name() const { return _studentName; }
        void Name(std::string x) { _studentName = std::move(x); }

        int Grade() const { return _studentGrade; }
        void Grade(int x) { _studentGrade = std::move(x); }
};

Aucun commentaire:

Enregistrer un commentaire