Hello,
I want to swap elements of an array but I have an error. Why?
Severity Code Description Project File Line Suppression State
Error C2676 binary '[': 'Student' does not define this operator or a conversion to a type acceptable to the predefined operator
Perhaps if you gave your variables better names, the issue might be more obvious.
You have an array of students called "myStudent" (singular).
You then create a variable called TStudent on line 28.
But then, on line 30, you attempt to assign myStudent (your array of students) to myStudent[j] (a Student).
You'd (generally) prefer pointers if it's large sizes of data per element. If each element in the array is relatively small, even if you have thousands of elements, you'd still prefer by-value swaps rather than dealing with pointers, since using pointers could cause tons of cache misses. (But in this case, since std::strings already have a pointer in them, I imagine the benefits either way are little. Just a guess, didn't measure.)