mercredi 3 mars 2021

How do I improve the following piece of code in constructor method?

auto MyName = "Luffy";
for (auto &student: students)
{
    if (student.name == MyName)
    {
        m_student_info = &student;
    }
}

students is a struct with names and rollnumbers declared somewhere with values. How do I improve this piece of code inside a constructor? return cannot be used inside the constructor. even when student.name finds a match, it still continues to run in loop, how to avoid that?

Aucun commentaire:

Enregistrer un commentaire